home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / t3_1 / manual.txt < prev    next >
Text File  |  1993-07-09  |  344KB  |  8,290 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.                                  THE T MANUAL
  14.  
  15.                                 Fourth Edition
  16.                                10 September 1988
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.                                Jonathan A. Rees
  31.                                 Norman I. Adams
  32.                                 James R. Meehan
  33.                                 Yale University
  34.  
  35.  
  36.          Copyright 1988 Computer Science Department, Yale University,
  37.                                  New Haven CT
  38.   
  39.                                modified version, 
  40.                                  alk, 12/23/88
  41.  
  42.  
  43.  
  44.                                     Preface
  45.  
  46. This  manual  describes  T,  a programming language being developed at the Yale
  47. University   Computer   Science   Department [Rees82],    and    its    current
  48. implementations.  It is a reference manual, intended to define the language and
  49. to describe the general direction of its development.  It is not intended as an
  50. introduction or a tutorial.
  51.  
  52. The  bulk  of  this  document  describes T as a programming language.  However,
  53. chapters 17, 18, and 19 describe pragmatic features which are specific  to  the
  54. current  implementations.   To help underscore the distinction between language
  55. and implementation, the implementations are referred to not as T but as Tau.
  56.  
  57. The reader is expected to have some programming experience; the reader may also
  58. find a knowledge of Lisp helpful, although T is different enough from Lisp that
  59. prior experience with Lisp might actually be a hindrance.
  60.  
  61. Chapter F describes ways in which the language is deficient and  directions  in
  62. which  it is likely to grow.  Also, the implementations are not faithful to the
  63. language definition  presented  in  the  manual;  section  F.3  catalogs  known
  64. deviations.
  65.  
  66. Please  send  questions  and  comments  about the language, this manual, or the
  67. various implementations of the system,  via  ARPAnet  mail  to  Rees@Yale.ARPA,
  68. Usenet mail to ...decvax!yale-comix!rees, or via U.S.  Mail to
  69.  
  70.     Jonathan Rees
  71.     Department of Computer Science
  72.     Yale University
  73.     P.O. Box 2158 Yale Station
  74.     New Haven, Connecticut 06520
  75.     Telephone (203) 432-4666
  76.  
  77. Announcements  of  interest  to T users are regularly broadcast via Arpanet and
  78. Usenet electronic mail to the mailing  list  T-Users@Yale.ARPA;  send  mail  to
  79. T-Users-Request@Yale.ARPA  if  you  want  to be added to (or removed from) this
  80. list.    Send  reports  about  errors  in  the  manual  or  implementations  to
  81. T-Bugs@Yale.ARPA.
  82.  
  83. James R. Meehan's current address is:
  84.  
  85.     Cognitive Systems, Inc.
  86.     234 Church St.
  87.     New Haven, Connecticut 06510
  88.  
  89. The T project has been funded exclusively by the Computing Facility of the Yale
  90. Computer Science Department.
  91.  
  92. TOPS-20, VMS, and VAX are trademarks of Digital Equipment Corporation.   Domain
  93. and  Aegis are trademarks of Apollo Computer, Inc.  UNIX is a trademark of Bell
  94. Laboratories.
  95.                                       -i-
  96.  
  97.  
  98.  
  99.                              Notes on this edition
  100.  
  101. The fourth edition includes, among others, the following additions and changes,
  102. many of which correspond to new features in Tau version 2.7:  
  103.  
  104.    - New    procedures:      bitwise   logical   operators,   MAKE-LOCALE,
  105.      MAKE-EMPTY-LOCALE, LOCALE?   *VALUE,  *DEFINE,  *LSET,  CHAR->STRING,
  106.      ASSERT,   SYNTAX-ERROR,   READ-ERROR,   PROJ1  et  al.,  OBJECT-HASH,
  107.      OBJECT-UNHASH,  WALK-WEAK-SET,    MAKE-LIST-READER,  MAKE-READ-TABLE,
  108.      MACRO-EXPANDER?,         INVOKE-MACRO-EXPANDER,         OBJECT-FILE?,
  109.      OBJECT-FILE-STREAM?,    TC-SYNTAX-TABLE,  
  110.      WRITE-LINE, WRITE-SPACES, MAKE-BROADCAST-PORT.
  111.  
  112.    - New    special    forms:    IMPORT,    MODIFY,   DEFINE-LOCAL-SYNTAX,
  113.      MACRO-EXPANDER, COMMENT, IGNORE, IGNORABLE.
  114.  
  115.    - New character names (LEFT-PAREN and others).
  116.  
  117.    - Escape character syntax explained.
  118.  
  119.    - Sample implementation of DELAY and FORCE provided.
  120.  
  121.    - Name   changes:   *THE-USER-ENV*   is   now   called        USER-ENV;
  122.      *THE-BASE-ENV*  is    STANDARD-ENV;  DEFINE-MACRO  is  DEFINE-SYNTAX;
  123.      GEN-ID is GENERATE-SYMBOL; SYMBOLCONC is CONCATENATE-SYMBOL.
  124.  
  125.    - Features withdrawn: FLOOR, CEILING,  ENV-LOOKUP,  CONS-FROM-FREELIST,
  126.      RETURN-TO-FREELIST, SET-DELIMITED-LIST-SYNTAX-IN-TABLE, dispatch read
  127.      macros.     [TC-MACRO-DEFINITION-ENV.]
  128.                                       -ii-
  129.  
  130.  
  131. This document is still far from finished.  Future work  required  includes  the
  132. following projects.
  133.  
  134.    - The  preface  ought  to  have  a  paragraph  or  two  describing  the
  135.      organization of the manual.
  136.  
  137.    - The "language overview" and "language principles" sections need to be
  138.      expanded.    There  should  be  a  description of the memory model of
  139.      objects, in which objects are modeled by pointers into memory.
  140.  
  141.    - The  form  of  procedure  and  special  form  description  should  be
  142.      explained.
  143.  
  144.    - The section on types needs expansion and examples.
  145.  
  146.    - Tail recursion should be explained.
  147.  
  148.    - MAKE-ECHO-STREAM should be described.
  149.  
  150.    - The external syntax of numbers should be described.  Chapter 14 needs
  151.      to give more detail.
  152.  
  153.    - Need to document HANDLER so that people know what to set a  structure
  154.      handler to.  Need to describe keyword clauses in OBJECT syntax.
  155.  
  156.    - There  should  be  examples  of  the use of JOIN in implementing type
  157.      hierarchies and heterarchies.
  158.  
  159.    - The introduction to the ports   chapter needs  work.    Also,    port
  160.      positions should be documented and implemented.
  161.  
  162.    - There  should  be  a  section  giving  a brief description of how the
  163.      implementation works at the machine level.  A full description should
  164.      be relegated to an independent document, which should be written.
  165.  
  166.    - Need  to discuss the VM system and reorganize the presentation of the
  167.      user interface.  Many more remarks on error  handling  and  debugging
  168.      are in order.
  169.                                      -iii-
  170.  
  171.  
  172.                                Acknowledgements
  173.  
  174. The authors wish to thank Kent Pitman for his continuing assistance in making T
  175. true.
  176.  
  177. Gerry Sussman has provided essential guidance and inspiration.
  178.  
  179. Guy Steele wrote most of the compiler we're using, and  has  otherwise  been  a
  180. strong  influence,  originating  much  of  the  project's design philosophy and
  181. shaping and inspiring many of its features.
  182.  
  183. This document borrows from the Lisp Machine Manual [WEINREB81] and  the  Common
  184. Lisp Reference Manual [STEELE81COM].  We are grateful to their authors.
  185.  
  186. We  wish  to  acknowledge the influence and valuable advice provided during the
  187. design process by the following people at  Yale,  MIT,  and  elsewhere:    Alan
  188. Bawden,  Richard  Bryan,  David  Byrne, George Carrette, William Clinger, Peter
  189. Deutsch, John Ellis, William Ferguson, Christopher Hanson, Carl Hoffman,  David
  190. Kranz,  David  Littleboy,  Drew  McDermott,  Nathaniel Mishkin, Robert Nix, Jim
  191. Philbin, John Ramsdell, Christopher Riesbeck, John  Ruttenberg,  Olin  Shivers,
  192. and Steve Wood.
  193.  
  194. Thanks to Judy Martel for her patient proofreading.
  195.  
  196. The  NIL  project  at MIT was the source of many of T's good ideas.  NIL is the
  197. work of Richard Bryan, Glenn Burke, George Carrette, Michael Genereseth, Robert
  198. Kerns, Jim Purtilo, John White, and one of the present authors (JR).
  199.  
  200. Jim   Purtilo  wrote  the  integer  arithmetic  package  used  in  the  current
  201. implementation while he was working on the NIL project.
  202.  
  203. We appreciate the patience of our user community, at Yale  and  elsewhere,  who
  204. have had to put up with an incompatible, incomplete, and untuned new system.
  205.  
  206. Finally,  we  wish  to  thank John O'Donnell for helping to shelter us from the
  207. real world, and for having the foresight, or perhaps  folly,  to  initiate  the
  208. project in the first place.
  209.                                       -iv-
  210.  
  211.  
  212.                                Table of Contents
  213.  
  214. 1. Introduction                                                               1
  215.  
  216.    1.1. Language overview                                                     1
  217.    1.2. Notational conventions                                                1
  218.    1.3. Naming conventions                                                    2
  219.    1.4. Language principles and conventions                                   3
  220.  
  221. 2. Syntax and semantics                                                       4
  222.  
  223.    2.1. External representation                                               4
  224.    2.2. Core language                                                         5
  225.    2.3. The standard environment                                              6
  226.    2.4. Undefined                                                             6
  227.  
  228. 3. Objects                                                                    7
  229.  
  230.    3.1. Literals                                                              7
  231.    3.2. Procedures                                                            8
  232.    3.3. Object identity                                                       8
  233.    3.4. Symbols                                                               8
  234.    3.5. Predicates and truth values                                           9
  235.    3.6. Types                                                                 10
  236.  
  237. 4. Environments                                                               11
  238.  
  239.    4.1. Environments and contours                                             11
  240.    4.2. Local variables                                                       12
  241.    4.3. Locales                                                               14
  242.    4.4. Non-local reference                                                   16
  243.  
  244. 5. Control                                                                    18
  245.  
  246.    5.1. Conditionals                                                          18
  247.    5.2. Iteration                                                             21
  248.    5.3. Procedure application                                                 22
  249.    5.4. Sequencing                                                            23
  250.    5.5. Non-local exits                                                       23
  251.    5.6. Lazy evaluation                                                       24
  252.  
  253. 6. Side effects                                                              25
  254.  
  255.    6.1. Assignment                                                           25
  256.    6.2. Locatives                                                            27
  257.    6.3. Dynamic state                                                        28
  258.  
  259. 7. Operations                                                                30
  260.  
  261.    7.1. Fundamental forms                                                    30
  262.    7.2. Defining operations                                                  33
  263.    7.3. Joined objects                                                       34
  264.    7.4. Synonyms                                                             34
  265.    7.5. Example                                                              35
  266.  
  267.                                      -v-
  268.  
  269.  
  270. 8. Numbers                                                                   36
  271.  
  272.    8.1. Predicates                                                           36
  273.    8.2. Arithmetic                                                           37
  274.    8.3. Comparison                                                           38
  275.    8.4. Sign predicates                                                      39
  276.    8.5. Transcendental functions                                             40
  277.    8.6. Bitwise logical operators                                            41
  278.    8.7. Coercion                                                             42
  279.    8.8. Assignment                                                           42
  280.  
  281. 9. Lists                                                                     43
  282.  
  283.    9.1. Predicates                                                           43
  284.    9.2. Constructors                                                         44
  285.    9.3. List access                                                          44
  286.    9.4. Lists as sequences                                                   46
  287.    9.5. Lists as sets                                                        47
  288.    9.6. Mapping Procedures                                                   48
  289.    9.7. Lists as associations                                                49
  290.    9.8. Lists as stacks                                                      49
  291.  
  292. 10. Trees                                                                    50
  293.  
  294.    10.1. Comparison                                                          51
  295.    10.2. Tree utilities                                                      51
  296.    10.3. Destructuring                                                       52
  297.    10.4. Quasiquote                                                          53
  298.  
  299. 11. Structures                                                               55    X11
  300.  
  301.    11.1. Terminology                                                         55
  302.    11.2. Defining structure types                                            55
  303.    11.3. Manipulating structure types                                        56
  304.    11.4. Manipulating structures                                             58
  305.  
  306. 12. Characters and strings                                                   60
  307.  
  308.    12.1. Predicates                                                          61
  309.    12.2. Comparison                                                          62
  310.    12.3. String constructors                                                 63
  311.    12.4. String access                                                       63
  312.    12.5. String manipulation                                                 65
  313.    12.6. String header manipulation                                          65
  314.    12.7. Case conversion                                                     66
  315.    12.8. Digit conversion                                                    66
  316.    12.9. ASCII conversion                                                    67
  317.    12.10. Symbols                                                            68
  318.  
  319. 13. Miscellaneous features                                                   69
  320.  
  321.    13.1. Comments and declarations                                           69
  322.    13.2. Errors and dead ends                                                69
  323.    13.3. Early binding                                                       71
  324.    13.4. Symbol generators                                                   71
  325.    13.5. Combinators                                                         71
  326.    13.6. Vectors                                                             73
  327.    13.7. Pools                                                               75
  328.    13.8. Weak pointers                                                       75
  329.  
  330.                                     -vi-
  331.  
  332.  
  333. 14. Syntax                                                                   77
  334.  
  335.    14.1. The reader                                                          77    X10
  336.    14.2. Read tables and read macros                                         79    X10
  337.    14.3. Standard compiler                                                   81
  338.    14.4. Syntax tables                                                       82    X10
  339.    14.5. Defining syntax                                                     83
  340.    14.6. Local syntax                                                        84
  341.    14.7. Macro expanders                                                     85
  342.  
  343. 15. Ports                                                                    87
  344.  
  345.    15.1. General                                                             87
  346.    15.2. Port switches                                                       88
  347.    15.3. Input                                                               89
  348.    15.4. Output                                                              91
  349.    15.5. Formatted output                                                    92
  350.    15.6. Miscellaneous                                                       93
  351.    15.7. Example                                                             94
  352.  
  353. 16. Files                                                                    95
  354.  
  355.    16.1. File systems                                                        95
  356.    16.2. Filenames                                                           96
  357.    16.3. Files                                                               97
  358.  
  359. 17. Program structure                                                        100
  360.  
  361.    17.1. Environment structure                                               100
  362.    17.2. Source files                                                        101
  363.    17.3. File syntax                                                         101
  364.    17.4. Loading files                                                       102
  365.    17.5. File compilation                                                    103
  366.  
  367. 18. User interface                                                           105
  368.  
  369.    18.1. Invoking Tau                                                        105
  370.    18.2. Read-eval-print loops                                               106
  371.    18.3. Command levels                                                      107
  372.    18.4. Transcripts                                                         107
  373.    18.5. Customization                                                       108
  374.  
  375. 19. Debugging                                                                109
  376.    19.1. Errors                                                              109
  377.    19.2. Debugging utilities                                                 110
  378.    19.3. The inspector                                                       111
  379.    19.4. Debugging primitives                                                114
  380.    19.5. Miscellaneous                                                       115
  381.  
  382.                                     -vii-
  383.  
  384.  
  385. Appendix A: A meta-circular evaluator  .  .  .  .  .  .  .  .  .  .  .       116
  386.  
  387. Appendix B: Libraries.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .       120
  388.  
  389.    B.1. The data base                                                        120
  390.    B.2. Symbol tables                                                        121
  391.    B.3. List utilities                                                       122
  392.    B.4. Type-specific arithmetic                                             123
  393.  
  394. Appendix C: ASCII character conversion .  .  .  .  .  .  .  .  .  .  .       125
  395.  
  396. Appendix D: Equivalences.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .       126
  397.  
  398. Appendix E: Friendly advice.  .  .  .  .  .  .  .  .  .  .  .  .  .  .       129
  399.  
  400.    E.1. Comparison with other Lisp dialects                                  129
  401.    E.2. Incompatibilities                                                    129
  402.  
  403. Appendix F: Future work .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .       130
  404.  
  405.    F.1. Language design problems                                             130
  406.    F.2. Common Lisp influence                                                132
  407.    F.3. Bugs in the implementation                                           133
  408.  
  409. References                                                                   135
  410.  
  411. Index                                                                        136
  412.  
  413. ________________________________________________________________________________
  414.  
  415.                               Notice to the Reader
  416.  
  417. Marginal cross-references to the  T 3.0 Release Notes  and to the  T 3.1 release
  418. notes have been added to this variant of the fourth edition  T Reference Manual.
  419. They consist of marginal entries of the form Xn, where n is either a page number
  420. in the  T 3.0 Release Notes,  or an asterisk,  *,  signifying a reference to the
  421. T 3.1 release notes.  These cross-references do not  indicate  additions  to the
  422. language, such as the load-foreign  interface,  or  tables  (replacing  property
  423. lists), or the new call-with-current-continuation and new i/o procedures.    For
  424. more information on these, consult the release notes.                      --alk
  425.                                    -vii-
  426.  
  427.  
  428. Chapter 1                                                          Introduction
  429.  
  430.  
  431. 1.1. Language overview
  432.  
  433. T  is  a dialect of Lisp derived from SCHEME. [STEELE78REV] It is comparable in
  434. power and expressiveness to other recent Lisp dialects  such  as  Lisp  Machine
  435. Lisp, [WEINREB81]    Common    Lisp, [STEELE83COM]   and   NIL, [WHITE79]   but
  436. fundamentally more similar in spirit to SCHEME than these other Lisp dialects.
  437.  
  438. T endeavors to be a powerful, expressive language which also  permits  portable
  439. and  efficient  implementations.    T  is  a "modern" Lisp suitable for a broad
  440. variety  of  applications,   including   symbolic,   numerical,   and   systems
  441. programming, on a variety of machines.
  442.  
  443. T  draws  from many sources in its attempt to provide a complete yet simple and
  444. unified system.  For the most part, the language's designers are collators, not
  445. originators.  Common Lisp, NIL, and SCHEME have been the strongest influences.
  446.  
  447. Except  for  a restriction on the use of escape procedures (see the description
  448. of CATCH,page 23), the omission of TEST and the multiprocessing primitives, and
  449. a  few  changed  names (e.g., SET instead of ASET'), T includes as a subset the
  450. SCHEME dialect described in The Revised Report on SCHEME [STEELE78REV].
  451.  
  452. 1.2. Notational conventions
  453.  
  454. The symbol "=>"  is used to indicate evaluation.  (Evaluation is  described  in
  455. section  2.2.)   For example, (+ 3 5) => 8 means that evaluating the expression
  456. (+ 3 5) yields 8.
  457.  
  458. The symbol "<=>"  indicates code equivalence.  For example, 
  459.  
  460.     (CAR (CDR x)) <=> (CADR x)
  461.  
  462. means that for any x, the value and effects of (CAR (CDR  x))  are  always  the
  463. same as the value and effects of (CADR x).
  464.  
  465. The  symbol  "->"   is used in definitions to indicate the type of result.  For
  466. example, 
  467.  
  468.     (NUMBER? object) -> boolean
  469.  
  470. means that the procedure named NUMBER? yields a boolean result.
  471.  
  472.     (PRINT object port) -> undefined
  473.  
  474. means that PRINT returns a value of no particular interest; that is, one should
  475. not depend on it to return anything in particular.
  476.  
  477. Italicized  names in the code examples are meta-variables that stand for pieces
  478. of code to be filled in.  Restrictions on the particular types or values  of  a
  479. meta-variable  are  often  suggested  by  its  name  or  are  given in the text
  480. associated with the example.  The term  object  denotes  data  of  unrestricted
  481. type.
  482.  
  483. Dot-notation,  as in (ADD . numbers), is used where any number of sub-forms are
  484. permitted.  In this example, there may be zero or more numbers; the description
  485. subsumes cases such as (ADD), (ADD 3), and (ADD 3 5 2).
  486.  
  487.                                       -1-
  488.  
  489. Some routines described in this manual, such as VREF (page 74), serve as access
  490. routines in the sense that they are appropriate for  use  in  SET  and  related
  491. forms  to  designate locations.  These routines have their descriptions flagged
  492. with the notation Settable.
  493.  
  494. 1.3. Naming conventions
  495.  
  496. Below are listed some of the naming conventions used for standard T procedures,
  497. variables, and reserved words.
  498.  
  499. ...?            The  suffix  ?  indicates a predicate.  For example, ZERO? is a
  500.                 predicate which returns true if  its  argument  is  numerically
  501.                 equal to zero.
  502.  
  503. ...!            The   suffix   !   indicates  a  side-effecting  variant  of  a
  504.                 non-side-effecting procedure.  For  example,  REVERSE!  is  the
  505.                 same  as  REVERSE,  but  it  alters its argument, recycling the
  506.                 storage to form its result.
  507.  
  508. ...->...        Infix -> is used in names of  coercion  procedures,  which  are
  509.                 routines which perform conversions between objects of different
  510.                 types.  For example, given a string, STRING->LIST forms a  list
  511.                 of the characters in the string.
  512.  
  513. *...*           The  names of variables whose scope is not visually apparent to
  514.                 someone reading the program is usually bounded on  either  side
  515.                 with  *'s.    This  convention  is used for variables which are
  516.                 either not bound to procedures, or whose value is  intended  to
  517.                 change.
  518.  
  519. DEFINE-...      Relates  to  the  assignment  of  something in a permanent way.
  520.                 DEFINE   is   typically   used   for    defining    procedures,
  521.                 DEFINE-OPERATION to define generic operations, and so forth.
  522.  
  523. MAKE-...        Indicates a routine which creates an object of some type, given
  524.                 size  (and  sometimes  datatype)  information.    For  example,
  525.                 (MAKE-STRING 5) makes a string of length 5.
  526.  
  527. NOT-...         The  prefix "NOT-" means that the truth value of some predicate
  528.                 is complemented.  For example, (NOT-LESS? x y) is the  same  as
  529.                 (NOT (LESS? x y)).
  530.  
  531. ...CDR          Relates  to  the subtail or successive subtails of a list.  For
  532.                                                                     th
  533.                 example, while the procedure named NTH returns the n    element
  534.                 of a list, there is another procedure named NTHCDR that returns
  535.                      th
  536.                 the n   subtail.
  537.  
  538. ...Q            The presence of the trailing character "Q" on a name  typically
  539.                 means that the predicate "EQ?" is involved.  For example,
  540.  
  541.                     (MEMQ? x l)  <=>  (MEM? EQ? x l)
  542.  
  543.                                       -2-
  544.  
  545. 1.4. Language principles and conventions
  546.  
  547. The  design  of  T employs a number of conventions.  These conventions make the
  548. language more regular, predictable, and easy to learn.
  549.  
  550. Anonymity: objects are not tightly coupled to their names.
  551.  
  552. Locality: effects may be achieved locally.
  553.  
  554. Argument order: procedures which  extract  components  from  aggregate  objects
  555. generally  take  the  aggregate  object  as  the  first argument, and selection
  556. information (if any) as subsequent arguments.  Similarly, assignment procedures
  557. take  the aggregate object or location specification early, and the value to be
  558. stored last.
  559.  
  560. Indexing: where numeric indices are involved, the indices begin with  zero  and
  561. range  up  to  a  given  limit.    Ranges are specified as half-open intervals,
  562. inclusive at the low end and exclusive at the high end.
  563.  
  564.                                       -3-
  565.  
  566. Chapter 2                                                  Syntax and semantics
  567.  
  568.  
  569. This chapter gives an overview of T as a programming language.  It is important
  570. not  to  confuse  the  language per se with a particular body of software which
  571. implements it.  It is natural that this  confusion  arises,  both  because  the
  572. language  and  its implementations have developed in parallel, and because this
  573. confusion is traditional among Lisp dialects (for  example,  Maclisp  and  Lisp
  574. Machine Lisp).
  575.  
  576. The T language logically comprises three distinct components:
  577.  
  578.    - an external representation for objects as character sequences,
  579.  
  580.    - a core language -- syntax and semantics for expressions, and
  581.  
  582.    - a  standard  environment  --  the  behavior  of the objects which are
  583.      values of system variables.
  584.  
  585. 2.1. External representation
  586.  
  587. Like  other  Lisp  dialects,  and  in  contrast  with  most  other  programming
  588. languages,  T has two different kinds of syntax: the external representation by
  589. which objects (data) are represented as a linear sequence of characters, and an
  590. expression  syntax  by which these objects can be understood as programs.  That
  591. is, the meaning of a T program represented as characters in  a  file  or  other
  592. external  storage  medium  must be determined in two stages:  first, by mapping
  593. the characters to objects, and then by interpreting these objects as executable
  594. programs.
  595.  
  596. The external syntax of T is very similar to that of other Lisp dialects, and is
  597. discussed in detail at appropriate places in this manual.  The following  gives
  598. only the most cursory description.
  599.  
  600. Characters  may  be  classified  according to their lexical properties; the two
  601. most important distinctions are between constituent and  delimiter  characters,
  602. and  between  read-macro characters and non-read-macro characters.  Alphabetic,
  603. numeric, and some special characters (e.g. - and $) are constituent characters;
  604. whitespace  and  some  special characters (e.g. left and right parenthesis) are
  605. delimiter characters.  Some special characters such as ( and '  are  read-macro
  606. characters;   these   introduce   special   syntactic   constructs   which  are
  607. idiosyncratic to the particular character introducing them.
  608.  
  609. A delimited sequence of consecutive constituent characters represents either  a
  610. number  or  a  symbol.  For example, 255 represents the integer 255, and APPEND
  611. and append both represent the symbol APPEND.  Here, and throughout the  manual,
  612. the  term symbol is being used in a technical manner to refer a particular kind
  613. of named object (see section 3.4).
  614.  
  615. Balanced parentheses with a sequence of (representations  of)  objects  between
  616. them  represent  a  list  of  the  (represented)  objects.    For  example, the
  617. characters (A B (C 12) D) represent a list of four objects, three of which  are
  618. symbols,  and one of which (the third one) is a list of two objects, the symbol
  619. C and the integer 12.  Parentheses which enclose no objects represent an  empty
  620. list.
  621.  
  622. There  are also external representations for strings and characters, as well as
  623. for some kinds of objects which are syntactically illegal as  expressions  (for
  624. example, vectors).  Not all objects have external representations, however.
  625.  
  626.                                       -4-
  627.  
  628.  
  629. 2.2. Core language
  630.  
  631. The  core  language  is described in terms of a hypothetical machine (called an
  632. evaluator) which executes T  code  directly.    In  practice,  the  existing  T
  633. implementations   have  (at  least)  two  evaluators,  both  of  which  perform
  634. evaluation as a two-stage process  consisting  of  compilation  (syntactic  and
  635. semantic analysis) followed by interpretation.
  636.  
  637. Evaluation  is a process whereby an object called an expression  (the term form
  638. is used synonymously with expression) is mapped to another object,  called  its
  639. value.   Evaluation occurs in the context of a particular variable environment;
  640. see below.  The expression is said to yield its value.
  641.  
  642. The evaluation mapping is not a purely  mathematical  mapping,  since  in  some
  643. cases  the  evaluation  of  an  expression  may depend not only on the variable
  644. environment but on the state of the running T system, or on the  state  of  the
  645. world  outside  it;  and evaluation may cause changes in the state of system or
  646. the world, which may, in turn, affect future evaluations.  These state  changes
  647. are called side-effects.
  648.  
  649. An  evaluator  for the core language, written in T, can be found in Appendix A.
  650. This program simply encodes in a formal way the evaluation  process  (that  is,
  651. the semantics) described informally below.
  652.  
  653. The rules by which an object is evaluated are as follows:
  654.  
  655. Self-evaluating   literals:      All   numbers,  strings,  and  characters  are
  656. syntactically valid expressions which, when evaluated, yield themselves.    For
  657. example,
  658.  
  659.     -2102        =>  -2102
  660.     #\M          =>  #\M
  661.     "A string."  =>  "A string."
  662.  
  663. The  notation  "expression  =>  value"  means  that expression, when evaluated,
  664. yields value.  (Note also that we are making use of the external object  syntax
  665. itself as a notational device:  "the object -2102" could be said more precisely
  666. as "an object externally represented by the characters `-2102'."    Just  as  a
  667. program  should never be confused with an object which represents it, an object
  668. should never be confused with a sequence of characters which notates it.)
  669.  
  670. Symbols:   As  evaluable  expressions,  symbols  are  interpreted  as  variable
  671. references.   A symbol evaluates to its value according to the current variable
  672. environment.  For example, in an environment in which the  variable  DELTA  has
  673. the value 15, evaluating the expression DELTA will yield 15.
  674.  
  675. Symbols  have many uses other than as names for variables.  It is important not
  676. to confuse the use of a symbol as a datum manipulated by  a  program  with  the
  677. occurrence  of  a  symbol as a variable reference in a program.  Symbols do not
  678. have values a priori; variables only have values by virtue of  the  context  in
  679. which they occur.
  680.  
  681. Lists:  Non-empty lists are classified either as calls or as special forms.  If
  682. the first element of the list is a symbol, and the symbol is a  reserved  word,
  683. then  the  list  is a special form; otherwise it is considered to be a call.  T
  684. reserved words include,  for  example,  the  symbols  QUOTE,  IF,  and  LAMBDA.
  685. (However, see section 14.4.)
  686.  
  687.                                       -5-
  688.  
  689.  
  690. Special forms:  The syntax and semantics of a special form are idiosyncratic to
  691. the  reserved  word  which  introduces  it;  descriptions  of  the  meaning  of
  692. expressions  introduced by the various reserved words are therefore distributed
  693. throughout the manual.
  694.  
  695. Calls:    Calls are evaluated as follows: the elements of the  list  (including
  696. the first) are evaluated, in no particular order.  The first must evaluate to a
  697. procedure; this procedure is applied  to the rest  of  the  values,  which  are
  698. called arguments.  (The verbs call and invoke mean the same as apply.)
  699.  
  700. 2.3. The standard environment
  701.  
  702. The  standard environment corresponds to what is usually known as the "run-time
  703. library" in other language environments such as C or Pascal.
  704.  
  705. New variable environments may be introduced in various ways  (see  chapter  4),
  706. but  a  T  system is obliged to supply one standard environment in which system
  707. variables are bound to system procedures and  constants,  as  defined  by  this
  708. manual.   Program execution typically occurs in an environment inferior to this
  709. standard environment (see section 17.1),  so  that  these  objects  are  easily
  710. accessible  as  values  of  lexically apparent variables.  For example, in this
  711. standard environment, the variable CONS has a certain procedure as its value.
  712.  
  713. For the most part, the values of system variables are procedures, and therefore
  714. the only behavior of interest is what they do when called.  (See the discussion
  715. of calls, above.)  In other cases,  values  are  objects  such  as  numbers  or
  716. symbols.
  717.  
  718. A  representation  of  the  standard  environment  is available as the value of
  719. STANDARD-ENV (page 100).
  720.  
  721. 2.4. Undefined
  722.  
  723. The term undefined is used in two different ways in this manual.  An expression
  724. may  yield  an  undefined  value,  in  which  case  it  yields  some value, the
  725. particular value not being defined by this manual.  In such cases it is  unwise
  726. to  depend on this value having any particular characteristics, for example, it
  727. being null, or not a number, or whatever.  The evaluation of the expression and
  728. the  creation  of  the undefined value are not in error; it is the use to which
  729. this value is put that may lead to problems.   Expressions  yielding  undefined
  730. values are generally useful only for any side-effects they cause.
  731.  
  732. On  the  other  hand,  the  evaluation  of  an expression may have an undefined
  733. effect, in which case an  implementation  will  endeavor  to  signal  an  error
  734. condition,  permitting  a user to take appropriate action.  For example, a call
  735. to a non-procedure, or adding two symbols together, have undefined effects.  An
  736. implementation  is not obliged, however, to signal an error, and in fact it may
  737. be  in  the  interest  of  efficiency  to  avoid  the  overhead  of   detecting
  738. circumstances under which undefined effects will happen.
  739.  
  740. The two procedures UNDEFINED-VALUE and UNDEFINED-EFFECT are used for expository
  741. purposes in examples throughout this manual;  they  are  described  in  section
  742. 13.2.
  743.  
  744.                                       -6-
  745.  
  746.  
  747. Chapter 3                                                               Objects
  748.  
  749.  
  750. T  is  an object-oriented language.  T programs are concerned for the most part
  751. with creating and manipulating objects, which represent all data, and form  the
  752. currency  of  computation  in  T.  Particular  objects  are  defined not by bit
  753. patterns or by addresses within a computer but rather by  their  behavior  when
  754. called or when passed to procedures which manipulate them.
  755.  
  756. Objects are obtained most primitively through the use of QUOTE (page 7), LAMBDA
  757. (page 8), and OBJECT (page 31) special forms, and less primitively  by  calling
  758. procedures  defined  in  the standard environment, e.g. CONS and COMPOSE, which
  759. create new objects or return existing ones.   (An  implementation  of  T  would
  760. presumably   define   many   such   procedures   using  more  primitive  object
  761. constructors; for example, COMPOSE might  be  defined  by  a  T  program  which
  762. employs  LAMBDA to construct the composed procedure.  Thus the question of what
  763. kinds of objects are truly primitive and which are not is  left  unanswered  by
  764. this manual.)
  765.  
  766. 3.1. Literals
  767.  
  768. As  described  in  section 2.2, some expressions evaluate "to themselves" or to
  769. copies of themselves.  These include numbers, strings, and characters, and  are
  770. called  self-evaluating literals.  However, some expressions, lists and symbols
  771. in particular, do not evaluate to themselves.  When an  expression  yielding  a
  772. particular   constant  value  is  required,  it  is  necessary  to  use  QUOTE.
  773. Self-evaluating literals and quoted constants are called literals.
  774.  
  775. Although not all objects have external representations, some objects  which  do
  776. have  external  representations  have  undefined  evaluation  semantics.  These
  777. include vectors (section 13.6) and the empty list.  QUOTE must also be used  to
  778. obtain these values as constants.
  779. (QUOTE object) -> object                                           Special form
  780.  
  781.      Yields object.  The object is not evaluated; thus QUOTE provides a literal
  782.      notation for constants.
  783.  
  784.          (QUOTE A)          =>  A
  785.          (QUOTE (A B))      =>  (A B)
  786.          (QUOTE (+ X 8))    =>  (+ X 8)
  787.          (QUOTE (QUOTE A))  =>  (QUOTE A)
  788.  
  789.      Since QUOTE is used so  frequently,  an  abbreviated  external  syntax  is
  790.      provided   for   QUOTE   forms:   'object   is   an  alternative  external
  791.      representation for the list (QUOTE object).
  792.  
  793.          'A          =>  A
  794.          '(A B)      =>  (A B)
  795.          '(QUOTE A)  =>  (QUOTE A)
  796.          ''A         =>  (QUOTE A)
  797.  
  798.      Objects returned by literal expressions are read-only; they should not  be
  799.      altered using SET or any other side-effecting form.
  800.  
  801.                                       -7-
  802.  
  803.  
  804. 3.2. Procedures
  805.  
  806. A  procedure  (or  routine)  is  any object which may be called.  Ordinarily, a
  807. procedure is called as a result of the evaluation of a call (page 3).  The most
  808. primitive mechanism for creating procedures is the LAMBDA special form.
  809. (LAMBDA variables . body) -> procedure                             Special form
  810.  
  811.      A  LAMBDA-expression  evaluates  to  a  procedure.   When the procedure is
  812.      called, the variables are bound to the arguments  to  the  call,  and  the
  813.      body,  an  implicit block, is evaluated.  The call yields the value of the
  814.      last form in the body.
  815.  
  816.          ((LAMBDA (X Y) (LIST Y X)) 7 'FOO)  =>  (FOO 7)
  817.  
  818.      If variables is not a proper list, but  ends  in  a  symbol  x,  then  the
  819.      variable  x  will  be  bound  to  a list of the arguments beginning at the
  820.      position corresponding to x.
  821.  
  822.          ((LAMBDA (X . Y) (LIST Y X)) 7 'FOO 'BAZ)  =>  ((FOO BAZ) 7)
  823.          ((LAMBDA Y Y) 7 'FOO 'BAZ)                 =>  (7 FOO BAZ)
  824.  
  825.      If any variable is () instead of a symbol, then the corresponding argument
  826.      in a call is ignored.
  827.  
  828.      Scoping:    The  values  of  the bound variables are apparent only in code
  829.      lexically contained in the body  of  the  LAMBDA-expression,  and  not  to
  830.      routines  called from the body.  That is, like SCHEME and ALGOL and unlike
  831.      most Lisp dialects, T is a lexically scoped language,  not  a  dynamically
  832.      scoped language.
  833.  
  834.      Closure:    The procedure is said to be a closure of the LAMBDA-expression
  835.      in the current lexical environment.  That is, when  procedure  is  called,
  836.      the body is evaluated in an environment which is the same as that in which
  837.      the LAMBDA-expression was evaluated, augmented  by  the  bindings  of  the
  838.      variables.   For example, if Z is mentioned in the body, and it is not one
  839.      of the variables, then it refers to whatever  Z  was  in  scope  when  the
  840.      LAMBDA-expression  was  evaluated, not (necessarily) to the the variable Z
  841.      that is in scope when procedure is called.
  842.  
  843.  
  844. 3.3. Object identity
  845.  
  846. Every object has identity, in the sense that  one  may  determine  whether  two
  847. given values are the same object.
  848.  
  849. In the following:
  850.  
  851.     (DEFINE A (LIST 'P 'Q))
  852.     (DEFINE B (LIST 'P 'Q))
  853.  
  854. there  is  no way (other than EQ?) to distinguish the two objects which are the
  855. values of A and B.  Nonetheless, since LIST is defined to return a  new  object
  856. each time it is called, the two objects are distinct; and indeed, a side-effect
  857. to one object will not affect the value of the other:
  858.  
  859.     (SET (CAR A) 'R)
  860.     A  =>  (R Q)
  861.     B  =>  (P Q)
  862.  
  863.                                       -8-
  864.  
  865.  
  866. Some system procedures and special forms  create  new  objects,  others  return
  867. objects which already exist.  In some cases, it is not defined which of the two
  868. happens;  it  is  only   guaranteed   that   some   object   with   appropriate
  869. characteristics  is  returned.    For  example, CONS creates new objects; QUOTE
  870. expressions yield pre-existing constant objects; and numerical routines such as
  871. + may or may not create new numbers.
  872.  
  873. The EQ? predicate primitively determines object identity.
  874. (EQ? object1 object2) -> boolean                                               
  875.  
  876.      Returns  true if object1 and object2 are identically the same object.  EQ?
  877.      is the finest comparison predicate for objects, in the sense that  if  EQ?
  878.      cannot  distinguish  two  objects,  then  neither  can  any other equality
  879.      predicate.
  880.  
  881.  
  882. (NEQ? object1 object2) -> boolean                                              
  883.  
  884.      NEQ? is the logical complement of EQ?.
  885.  
  886.          (NEQ? object1 object2) <=> (NOT (EQ? object1 object2))
  887.  
  888.  
  889. Uniqueness of literals (other than symbols and  characters)  isn't  defined  in
  890. general.  For example,
  891.  
  892.     (EQ? '(A B C) '(A B C))
  893.  
  894. may  yield  either  true  or  false,  depending  on  the  implementation.   Two
  895. similar-looking literal expressions in different places may or  may  not  yield
  896. distinct objects.
  897.  
  898. However, a given literal expression will always yield the same object each time
  899. it is evaluated.
  900.  
  901.     (LET ((F (LAMBDA () '(A B C)))) (EQ? (F) (F)))  ->  true
  902.  
  903. 3.4. Symbols
  904.  
  905. Symbols  are  named  objects  which  have  wide  applicability  as  tokens  and
  906. identifiers  of various sorts.  Symbols are uniquely determined by their names,
  907. and have a convenient external syntax by which they may be obtained.
  908.  
  909. Uniqueness of symbols is defined:
  910.  
  911.     (EQ? 'FOO 'FOO)  =>  true
  912.  
  913. (SYMBOL? object) -> boolean                                      Type predicate
  914.  
  915.      Returns true if object is a symbol.
  916.  
  917.  
  918. See also SYMBOL->STRING and STRING->SYMBOL, page 68.
  919.  
  920.                                       -9-
  921.  
  922.  
  923. 3.5. Predicates and truth values
  924.  
  925. Conditional expressions in T (see section 5.1) usually involve  the  evaluation
  926. of  a  test  expression;  the object yielded by the test is then used to make a
  927. control decision, depending on whether the value is false or true.    There  is
  928. one  false  value; this is a distinguished object called null.  Any other value
  929. is considered to be true.  A value intended to be used in this way is called  a
  930. truth value.
  931.  
  932. A  predicate  is  any  procedure  which  yields  truth  values.  Predicates are
  933. typically given names which end in ?, e.g. NULL? and EQ?.  Calls to  predicates
  934. are naturally used as test expressions.
  935.  
  936. An  equality predicate is a two-argument predicate which is side-effectless and
  937. unaffected by side-effects, and  acts  like  an  equivalence  relation  in  the
  938. mathematical sense.
  939. NIL -> false                                                                       X6,7
  940.  
  941.      This  system  variable  has as its value the object null.  Null serves two
  942.      distinct purposes in T:  it is the standard false value,  as  returned  by
  943.      test  expressions  and tested by conditionals; and it is the empty list, a
  944.      list which has no elements.  Null's external representation is ().
  945.  
  946.      (Programmers with prior LISP experience should note  that  in  most  other
  947.      dialects  of LISP, null and the symbol NIL are identical.  This is not the
  948.      case in T: 'NIL => NIL, but NIL =>  (), and (EQ? NIL 'NIL) is false.)
  949. T -> true                                                                          X6
  950.  
  951.      The system variable T has as  its  value  a  standard  true  value.    The
  952.      identity  of  this  value  is  unimportant,  since  any non-false value is
  953.      considered to be true for the purposes of tests.
  954.  
  955.  
  956. 3.6. Types
  957.  
  958. A type may be seen either as a collection of objects with similar behavior,  or
  959. as  a  characteristic  function  for  such  a  collection,  or  as the behavior
  960. characteristic of similar objects; these views are equivalent.
  961.  
  962. A type predicate is a predicate which is defined on all objects and whose value
  963. is  not  affected by any side-effects (that is, calling the type predicate on a
  964. particular object will return the same value regardless of the point  at  which
  965. it  is  called  with respect to arbitrary other computations).  Type predicates
  966. are usually used to determine a given object's membership in a type.
  967.  
  968.                                      -10-
  969.  
  970.  
  971. Chapter 4                                                          Environments
  972.  
  973.  
  974. 4.1. Environments and contours
  975.  
  976. Environments are associations between identifiers (variable names) and  values.
  977. One such association between an identifier and a value is called a binding.  In
  978. general,  environments  are  created  implicitly,  for  example,  on   entering
  979. LAMBDA-bodies.
  980.  
  981. Environments are organized hierarchically into contours.  Each contour augments
  982. an "outer" environment, providing  bindings  for  a  few  identifiers.    These
  983. bindings  are  in  effect  in  the  body of the expression which introduces the
  984. contour.  The portion of a program in which a binding is in effect is known  as
  985. the variable's scope.
  986.  
  987. For example:
  988.  
  989.     (BLOCK
  990.      (LIST 'A 'B)
  991.      ...
  992.      (LAMBDA (A B C)
  993.        ...                  ; [1]
  994.        (LAMBDA (D E)
  995.          ...                ; [2]
  996.          )
  997.        ...                  ; [3]
  998.        (LAMBDA (A F G)
  999.          ...                ; [4]
  1000.          )
  1001.        ...)
  1002.      ...)
  1003.  
  1004. Each  LAMBDA  introduces  a  new  contour.    This code presumably occurs in an
  1005. outermost environment in which the variable LIST is  bound.    (The  values  of
  1006. BLOCK  and  LAMBDA are not in question here; they are reserved words, and their
  1007. bindings as variables are irrelevant.)  At point [1]  in  the  program,  a  new
  1008. environment is in effect which now has bindings for A, B, and C, as well as for
  1009. any variables known in the outer environment.   At  [2],  D  and  E  also  have
  1010. values.    [3]  is in the scope of A, B, and C but not in the scope of D and E.
  1011. Finally, the outer binding  of  any  given  identifier  is  shadowed  by  inner
  1012. bindings of that identifier; an occurrence of the identifier A appearing at [4]
  1013. refers not to the outer A but to the inner one, because the inner  one  shadows
  1014. the outer.
  1015.  
  1016. There  are  two  kinds  of  contours,  known  as  lambda-contours  and locales.
  1017. Lambda-contours are introduced by many special forms, such as LAMBDA, LET,  and
  1018. LABELS.  Locales are introduced by LOCALE special forms.
  1019.  
  1020.                                      -11-
  1021.  
  1022.  
  1023. 4.2. Local variables
  1024.  
  1025. (LET specs . body) -> value-of-body                                Special form
  1026.  
  1027.      LET  provides  a  convenient  syntax for introducing local bindings.  Each
  1028.      spec should be a two-element list of the form (variable value).  The value
  1029.      expressions  are all evaluated (in no particular order), then the body (an
  1030.      implicit block) is evaluated in an environment  where  the  variables  are
  1031.      bound to those values.  The value of body is yielded.
  1032.  
  1033.          (LET ((X 2)) X)  =>  2
  1034.  
  1035.          (LET ((var  val ) (var  val ) ... (var  val )) . body)
  1036.                    1    1      2    2          n    n
  1037.          <=> ((LAMBDA (var  var  ... var ) . body) val  val  ... val )
  1038.                           1    2        n             1    2        n
  1039.      See also DESTRUCTURE (page 52).
  1040.  
  1041.  
  1042. (LET* specs . body) -> value-of-body                               Special form
  1043.  
  1044.      LET*  is  like LET, except that the binding of variables to values is done
  1045.      sequentially, so that the second binding is  done  in  an  environment  in
  1046.      which  the  first binding has already occurred, etc.  In a LET-expression,
  1047.      all the bindings are done in one environment.
  1048.  
  1049.      For example, suppose the variable A  is  already  bound  to  10  when  the
  1050.      expression (LET ((A 20) (B A)) B) is evaluated.  The result is 10, not 20,
  1051.      because B is bound to A's value in the outer environment.    In  contrast,
  1052.      (LET* ((A 20) (B A)) B) evaluates to 20.
  1053.  
  1054.          (LET* ((var  val ) (var  val ) ... (var  val )) . body)
  1055.                     1    1      2    2          n    n
  1056.            <=>
  1057.          (LET ((var  val ))
  1058.                    1    1
  1059.            (LET ((var  val ))
  1060.                      2    2
  1061.                 ...
  1062.                 (LET ((var  val )) . body)...))
  1063.                           n    n
  1064.            <=>
  1065.          ((LAMBDA (var )
  1066.                       1
  1067.             ((LAMBDA (var )
  1068.                          2
  1069.                 ...
  1070.                 ((LAMBDA (var ) . body)
  1071.                              n
  1072.                  val ) ...)
  1073.                     n
  1074.              val ))
  1075.                 2
  1076.           val )
  1077.              1
  1078.  
  1079.                                      -12-
  1080.  
  1081.  
  1082. (LABELS specs . body) -> value-of-body                             Special form
  1083.  
  1084.      LABELS  is  useful  for  defining  local  procedures  that may be mutually
  1085.      recursive.  Each spec should  be  of  the  form  (variable  value).    The
  1086.      value-expressions  are evaluated (in no particular order), and the body is
  1087.      evaluated in an environment where all the variables  are  bound  to  those
  1088.      values.    However,  LABELS  differs  from LET in that the bindings of the
  1089.      variables are already in effect (scope) before the  value-expressions  are
  1090.      evaluated,  so  that  the  value-expressions  can  refer  to  any  of  the
  1091.      variables, including the ones to which they themselves will be bound (thus
  1092.      permitting local recursive procedures).
  1093.  
  1094.      Each spec may alternatively have the form
  1095.  
  1096.          ((variable . argument-vars) . body).
  1097.  
  1098.      This is equivalent to
  1099.  
  1100.          (variable (LAMBDA argument-vars . body))
  1101.  
  1102.      This is intended to parallel the syntax for DEFINE (see page 15).
  1103.  
  1104.      In  the following example, note that REV-1 is bound to a value that refers
  1105.      to REV-1.
  1106.  
  1107.          (DEFINE (REVERSE L)
  1108.            (LABELS (((REV-1 L RESULT-SO-FAR)
  1109.                      (COND ((NULL? L) RESULT-SO-FAR)
  1110.                            (ELSE
  1111.                              (REV-1 (CDR L)
  1112.                                     (CONS (CAR L) RESULT-SO-FAR))))))
  1113.              (REV-1 L '())))
  1114.  
  1115.      As an extension to the dialect of  SCHEME  described  in [STEELE78REV],  T
  1116.      does   not  restrict  the  value  expressions  to  be  LAMBDA-expressions.
  1117.      However, the values of  the  variables  are  not  defined  until  body  is
  1118.      evaluated;  i.e.,  they  should not be used in the value-expressions.  For
  1119.      example, 
  1120.  
  1121.          (LABELS ((A B) (B 1)) . body)
  1122.  
  1123.      is ill-formed; at the point  when  the  expressions  B  and  1  are  being
  1124.      evaluated,  the  variable  B  is  bound, but will have an undefined value.
  1125.      Consequently, A will have  an  undefined  value.    By  contrast,  in  the
  1126.      well-formed expression
  1127.  
  1128.          (LABELS ((A (LAMBDA (X) (+ X B))) (B 1)) . body),
  1129.  
  1130.      which can also be written
  1131.  
  1132.          (LABELS (((A X) (+ X B)) (B 1)) . body),
  1133.  
  1134.      the   value   of   B   is   not  used  before  body  is  evaluated.    The
  1135.      LAMBDA-expression evaluates to a closure that includes B.  By the  time  A
  1136.      (the closure) is called, B will have a value.
  1137.  
  1138.                                      -13-
  1139.  
  1140.  
  1141.      LABELS  cannot easily be described in terms of LAMBDA.  However, it can be
  1142.      described in terms of LAMBDA and  SET.    (SET  performs  side-effects  on
  1143.      bindings;  see  page 25.)  This is misleading because LABELS should not be
  1144.      thought of as a side-effecting operator.
  1145.  
  1146.  
  1147.          (LABELS ((var  val )
  1148.                       1    1
  1149.                   (var  val )
  1150.                       2    2
  1151.                   ...
  1152.                   (var  val ))
  1153.                       n    n
  1154.            . body)
  1155.             <=>
  1156.          (LET ((var  (UNDEFINED-VALUE))
  1157.                    1
  1158.                (var  (UNDEFINED-VALUE))
  1159.                    2
  1160.                ...
  1161.                (var  (UNDEFINED-VALUE)))
  1162.                    n
  1163.            (SET var  val )
  1164.                    1    1
  1165.            (SET var  val )
  1166.                    2    2
  1167.            ...
  1168.            (SET var  val )
  1169.                    n    n
  1170.            . body)
  1171.  
  1172.      This equivalence is overly concrete in that the order of evaluation of the
  1173.      val   expressions, and the sequence in which the variables are given their
  1174.         i
  1175.      values, is not defined.
  1176.  
  1177. 4.3. Locales
  1178.  
  1179. Locales serve two purposes.  First, they provide an incremental or  declarative
  1180. syntax  for  creating  variable  bindings  in  a contour.  Second, they provide
  1181. access to environments as objects which can be dynamically  manipulated.    The
  1182. term  locale  is  used  to  mean  both  the  kind  of  contour  introduced by a
  1183. LOCALE-expression, and the object which represents the environment.
  1184.  
  1185. There are no global variables in T; all variables are lexically bound  in  some
  1186. contour.    Locales  play  the  role  of what is known in other Lisp and Scheme
  1187. dialects as the global environment.
  1188. (LOCALE variable . body) -> value-of-body                          Special form    X8
  1189.  
  1190.      Introduces a locale and evaluates body (an implicit block)  in  it.    The
  1191.      value  of the LOCALE expression is that of body's last form.  Within body,
  1192.      variable is bound to the locale.  If variable is (), then  the  locale  is
  1193.      not accessible as an object.
  1194.  
  1195.                                      -14-
  1196.  
  1197.  
  1198.      [LOCALE has been removed from T>3.  Use MAKE-LOCALE, &c., instead.]
  1199.  
  1200.  
  1201. [(DECLARE ...)                                                    Reserved Word    X8
  1202.     
  1203.      In T>3 a new special form, DECLARE is introduced, but it's syntax has not
  1204.      yet been released publicly.]
  1205.  
  1206.  
  1207. (DEFINE variable value) -> undefined                               Special form
  1208. (DEFINE (variable . arguments) . body) -> undefined
  1209.  
  1210.      DEFINE creates a binding for variable in the lexically innermost locale in
  1211.      which  the  DEFINE  expression occurs.  The variable is given value as its
  1212.      value.
  1213.  
  1214.      The second DEFINE syntax is for defining procedures.
  1215.  
  1216.          (DEFINE (variable . arguments) . body)
  1217.  
  1218.      is equivalent to
  1219.  
  1220.          (DEFINE variable (LAMBDA arguments . body))
  1221.  
  1222.      For example:
  1223.  
  1224.          (DEFINE (F X) (LIST X 2))    <=>  (DEFINE F (LAMBDA (X) (LIST X 2)
  1225.          (DEFINE (F . X) (LIST X 2))  <=>  (DEFINE F (LAMBDA X (LIST X 2)))
  1226.  
  1227.  
  1228. (LSET variable value) -> value                                     Special form    X6
  1229.  
  1230.      LSET is identical to DEFINE except that the procedure definition syntax is
  1231.      not  permitted,  and  the variable is declared to be alterable.  Variables
  1232.      bound by DEFINE may not be altered with SET; variables bound by  LSET  may
  1233.      be.  See SET, page 25.
  1234.  
  1235.  
  1236. Any  LOCALE-expression  whose  variable  position  is () may be rewritten as an
  1237. expression involving only LET or LABELS.  In this case the  use  of  LOCALE  is
  1238. simply  a notational difference; using LOCALE instead of LET or LABELS may make
  1239. code easier or harder to read and manipulate.
  1240.  
  1241.     (LOCALE ()
  1242.       (DEFINE FOO ...)
  1243.       (DEFINE BAR ...)
  1244.       ...)
  1245.        <=>
  1246.     (LABELS ((FOO ...)
  1247.              (BAR ...))
  1248.       ...)
  1249.  
  1250. This transformation may not  be  possible  if  the  LOCALE-expression  binds  a
  1251. variable  to  the locale; in this case new bindings may be added as a result of
  1252. calls to *DEFINE or *LSET (see below), and there is no way to  anticipate  what
  1253. variables should be bound by the LABELS or LET expression.
  1254.  
  1255.                                      -15-
  1256.  
  1257.  
  1258. References  in  a  LOCALE  body  to variables bound later on in that locale are
  1259. undefined.  For example,
  1260.  
  1261.     (LET ((A 10)) (LOCALE () (LET ((B A)) (DEFINE A 20) B)))
  1262.  
  1263. has an undefined effect; it may yield 10 or 20, or it may signal an error.
  1264.  
  1265.      Rationale: The undefinedness of forward references permits implementations
  1266.      flexibility in dealing with the declarative nature  of  DEFINE  and  LSET.
  1267.      New  bindings may be registered either when encountered during evaluation,
  1268.      to simplify evaluation, or  may  be  registered  during  a  pre-processing
  1269.      (compilation)   phase,   to   permit   compilation  to  a  more  efficient
  1270.      representation.
  1271.  
  1272. (MAKE-LOCALE superior-locale identification) -> locale                         
  1273.  
  1274.      Creates a locale inferior to superior-locale.  Identification may  be  any
  1275.      object, and is used only for debugging purposes.
  1276.  
  1277.          (DEFINE *FOO-ENV* (MAKE-LOCALE STANDARD-ENV '*FOO-ENV*))
  1278.  
  1279.  
  1280. (MAKE-EMPTY-LOCALE identification) -> locale                                   
  1281.  
  1282.      Creates a locale containing no bindings whatsoever.
  1283.  
  1284.  
  1285. (LOCALE? object) -> boolean                                      Type predicate
  1286.  
  1287.      Returns true if object is a locale.
  1288.  
  1289.  
  1290. 4.4. Non-local reference
  1291.  
  1292. (*VALUE locale identifier) -> object                                   Settable
  1293.  
  1294.      Accesses the value of identifier in locale.  If identifier has no value in
  1295.      locale, then the effect of the call to *VALUE is undefined.
  1296.  
  1297.          (*VALUE STANDARD-ENV 'T)              =>  true
  1298.          (*VALUE (LOCALE Z (DEFINE A 10) Z) 'A)  =>  10
  1299.  
  1300.  
  1301. (*DEFINE locale identifier value) -> undefined                                 
  1302.  
  1303.      Defines the value of identifier in locale to be value.
  1304.  
  1305.  
  1306. (*LSET locale identifier value) -> value                                       
  1307.  
  1308.      Creates a binding for identifier in locale with initial value value.
  1309.  
  1310.                                      -16-
  1311.  
  1312.  
  1313. (IMPORT locale . variables) -> undefined                                       
  1314.  
  1315.      Locally defines variables to have the  same  values  as  their  values  in
  1316.      locale.
  1317.  
  1318.          (IMPORT locale var  var  ... var )
  1319.                            1    2        n
  1320.            <=>
  1321.          (BLOCK (DEFINE var  (*VALUE locale 'var ))
  1322.                            1                    1
  1323.                 (DEFINE var  (*VALUE locale 'var ))
  1324.                            2                    2
  1325.                 ...
  1326.                 (DEFINE var  (*VALUE locale 'var )))
  1327.                            n                    n
  1328.  
  1329.                                      -17-
  1330.  
  1331.  
  1332. Chapter 5                                                               Control
  1333.  
  1334.  
  1335. 5.1. Conditionals
  1336.  
  1337. (COND . clauses) -> value-of-clause                                Special form
  1338.  
  1339.      COND  is  a general conditional construct.  Each clause should have one of
  1340.      the following forms:  
  1341.  
  1342.         - (test . body)
  1343.  
  1344.         - (test)
  1345.  
  1346.         - (test => procedure)
  1347.  
  1348.      The test expressions are evaluated in sequence until one yields  true,  at
  1349.      which point:  
  1350.  
  1351.         - If  it is part of a clause of the form (test . body), then body,
  1352.           an implicit block, is evaluated,  and  its  value  is  what  the
  1353.           COND-expression yields.
  1354.  
  1355.         - If  the  clause  has  the  form (test), then the COND-expression
  1356.           yields the value of test (which of course is non-null).
  1357.  
  1358.         - If the clause  has  the  form  (test  =>  procedure),  then  the
  1359.           procedure  expression  is evaluated, and its value, which should
  1360.           be a procedure, is called with the value of the test as its  one
  1361.           and only argument.  The COND yields the value of that call.  
  1362.  
  1363.      Example:
  1364.  
  1365.          (COND ((PAIR? X)   (GAUR (CAR X)))
  1366.                ((FIXNUM? X) (GAUR X)))
  1367.  
  1368.      If  all  the  tests  yield false, then the COND yields an undefined value.
  1369.      See section 2.4 for a discussion of undefined values.
  1370.  
  1371.      The system variable ELSE has a non-null value.  This provides a convenient
  1372.      way to specify a branch to take when all other tests fail.
  1373.  
  1374.          (COND ((PAIR? X) (GAUR (CAR X)))
  1375.                ((ASSQ X *SAMPLE-ALIST*) => CDR)
  1376.                ((GAUR X))
  1377.                (ELSE NIL))
  1378.  
  1379.  
  1380. (XCOND . clauses) -> value-of-clause                               Special form
  1381.  
  1382.      Similar  to  COND, but its effect is undefined (and presumably an error is
  1383.      signalled) if no clause is selected.  X is mnemonic for "exhaustive".
  1384.  
  1385.  
  1386. ELSE -> true                                                                   
  1387.  
  1388.      ELSE has as its value some true value.  It exists mainly for use in  COND.
  1389.  
  1390.                                      -18-
  1391.  
  1392.  
  1393. (IF test consequent alternate) -> value-of-arm                     Special form
  1394. (IF test consequent) -> undefined
  1395.  
  1396.      IF  is a primitive two-way conditional.  The test expression is evaluated.
  1397.      If it yields true, then the consequent expression is evaluated, and the IF
  1398.      yields  its  value.    Otherwise,  the  alternate  expression,  if any, is
  1399.      evaluated, and the IF yields its value.  If test yields false and there is
  1400.      no alternate, then the value of the IF is undefined.
  1401.  
  1402.          (IF T 1 2)                 =>  1
  1403.          (IF (PAIR? 'X) 'FOO 'BAR)  =>  BAR
  1404.  
  1405.          (IF test consequent)  <=>  (IF test consequent (UNDEFINED-VALUE))
  1406.  
  1407.  
  1408. (CASE key . clauses) -> value-of-clause                            Special form
  1409.  
  1410.      CASE  performs  a  multi-way  dispatch  based  on  the  value  of  the key
  1411.      expression.  Each clause should be of the form (keys . body),  where  keys
  1412.      is  a list of values (not expressions!) against which the value of the key
  1413.      expression is compared (using EQ?), and body is an implicit  block.    The
  1414.      body  of  the  clause  which  matches  the key value is evaluated, and the
  1415.      CASE-expression yields the value of the body.  The last clause may  be  of
  1416.      the form (ELSE . body); this designates a default action to be taken if no
  1417.      other clause is selected.  If the  key  never  matches  and  there  is  no
  1418.      default clause, then the CASE-expression yields an undefined value.
  1419.  
  1420.          (CASE 'B ((A) 'LOSE) ((B C) 'WIN) (ELSE NIL))  =>  WIN
  1421.  
  1422.  
  1423. (XCASE key . clauses) -> value-of-clause                           Special form
  1424.  
  1425.      Similar  to  CASE,  but  no  ELSE-clause  is  permitted, and the effect is
  1426.      undefined (and presumably an error is signalled) if no clause is selected.
  1427.  
  1428.  
  1429. (SELECT key . clauses) -> value-of-clause                          Special form
  1430.  
  1431.      SELECT  is  like CASE, but the car of each clause is a list of expressions
  1432.      that are evaluated, instead of a list of constants.
  1433.  
  1434.          (DEFINE *RED-COLOR*   ...)
  1435.          (DEFINE *GREEN-COLOR* ...)
  1436.          (DEFINE *BLUE-COLOR*  ...)
  1437.          (SELECT COLOR
  1438.                  ((*RED-COLOR* *BLUE-COLOR*) 'INORGANIC)
  1439.                  ((*GREEN-COLOR*)            'ORGANIC))
  1440.  
  1441.  
  1442. (XSELECT key . clauses) -> value-of-clause                         Special form
  1443.  
  1444.      Similar to SELECT, but no ELSE-clause is  permitted,  and  the  effect  is
  1445.      undefined (and presumably an error is signalled) if no clause is selected.
  1446.  
  1447.                                      -19-
  1448.  
  1449.  
  1450. (NOT object) -> boolean                                          Type predicate
  1451. (FALSE? object) -> boolean
  1452.  
  1453.      NOT returns true if object is false, and returns false otherwise.
  1454.  
  1455.          (NOT NIL)  =>  true
  1456.          (NOT T)    =>  false
  1457.          (NOT 3)    =>  false
  1458.  
  1459.  
  1460. (AND . tests) -> value-of-test or false                            Special form
  1461.  
  1462.      The test expressions are evaluated from left to right, until one evaluates
  1463.      to  false,  at  which point the AND yields false.  If no test evaluates to
  1464.      false then the value of the AND is the value of the last test.
  1465.  
  1466.          (AND 3 4)    =>  4
  1467.          (AND 3 NIL)  =>  false
  1468.          (AND)        =>  true
  1469.  
  1470.  
  1471. (OR . tests) -> value-of-test or false                             Special form
  1472.  
  1473.      The test expressions are evaluated from left to right, until one evaluates
  1474.      to true (i.e., not null); its value is yielded as the value of the OR.  If
  1475.      no test evaluates to true, then the value of the OR is false.
  1476.  
  1477.          (OR 3 4)    =>  3
  1478.          (OR 3 NIL)  =>  3
  1479.          (OR)        =>  false
  1480.  
  1481.  
  1482. (*AND . objects) -> object                                                     
  1483.  
  1484.      If any of the objects is false, *AND returns false; otherwise  it  returns
  1485.      the  last  object.    This  is  superficially  similar to AND, but it is a
  1486.      procedure, not a special form.  That is, the value of *AND is a procedure,
  1487.      whereas  AND is a reserved word which introduces a special syntactic form.
  1488.      This fact implies that (a) the variable *AND has a value  suitable  to  be
  1489.      passed  as  an  argument to some procedure, and (b) a call to *AND behaves
  1490.      differently from an AND  special  form  in  the  case  that  the  argument
  1491.      expressions have side-effects.  In
  1492.  
  1493.          (AND NIL (FOO))
  1494.  
  1495.      FOO will not be called, whereas in
  1496.  
  1497.          (*AND NIL (FOO))
  1498.  
  1499.      FOO will be called.
  1500.  
  1501.  
  1502. (*OR . objects) -> object                                                      
  1503.  
  1504.      If  any  of  the  objects  is  true, *OR returns that object; otherwise it
  1505.      returns false.  *OR's relation to OR is analogous to  *AND's  relation  to
  1506.      AND.
  1507.  
  1508.                                      -20-
  1509.  
  1510.  
  1511. (*IF test consequent alternate) -> object                                      
  1512.  
  1513.      If  test  is true, *IF returns consequent; otherwise it returns alternate.
  1514.      *IF's relation to IF is analogous to *AND's relation to AND.
  1515.  
  1516.  
  1517. 5.2. Iteration
  1518.  
  1519. Separate iteration constructs are not strictly necessary in T, since  iteration
  1520. may  be  written using recursive procedures defined by LABELS (or even DEFINE).
  1521. There is no penalty for this in T, either in efficiency  or  practicality  (for
  1522. example,  stack  size),  because  tail-recursions  are  implemented without net
  1523. growth of stack, and  it  is  expected  that  compilers  will  implement  local
  1524. procedures efficiently.
  1525.  
  1526. However,  the  following  two  iteration  constructs  provide  a  somewhat more
  1527. convenient notation  for  loops  than  does  LABELS.    (There  are  also  some
  1528. higher-order  procedures which perform iteration; see for example MAP, page 48,
  1529. and WALK, page 48.)
  1530. (DO specs (end-test . exit-forms) . body) -> value-of-exit         Special form
  1531.  
  1532.      Iterates until end-test yields true.  Each spec  should  be  of  the  form
  1533.      (variable  initial  next).    The  variables  are  initialized  (bound) in
  1534.      parallel to the values of the initial-expressions, as with LET; then,  the
  1535.      end-test  and  body are executed iteratively.  If the end-test yields true
  1536.      on any iteration, then the loop terminates, at which point the  exit-forms
  1537.      are  evaluated.    The value of the DO-expression is the value of the last
  1538.      exit-form, or the value of the end-test if there are no  exit-forms  (this
  1539.      is   like   a   COND   clause).    At  the  end  of  each  iteration,  the
  1540.      next-expressions are all evaluated, and the variables are re-bound to  the
  1541.      values of the next-expressions.
  1542.  
  1543.      DO  is useful for loops which have a single termination condition, such as
  1544.      numerical,  ALGOL-style  for-loops,  loops  where  desired   results   are
  1545.      accumulated  in  variables,  and  loops that perform side-effects on every
  1546.      element in a sequence (see WALK, page 48).
  1547.  
  1548.          (REVERSE L)  <=>
  1549.            (DO ((L L (CDR L))
  1550.                 (RESULT '() (CONS (CAR L) RESULT)))
  1551.                ((NULL? L) RESULT)))
  1552.  
  1553.          (VECTOR-FILL VECTOR CONSTANT)  <=>
  1554.            (DO ((I (-1+ (VECTOR-LENGTH VECTOR)) (-1+ I)))
  1555.                ((<0? I) VECTOR)
  1556.              (VSET VECTOR I CONSTANT))
  1557.  
  1558.      Any DO-expression  may  be  rewritten  using  the  more  primitive  LABELS
  1559.      construct.   The following example has only one induction variable and one
  1560.      body-expression, and assumes that there are no  name  conflicts  with  the
  1561.      variable LOOP.
  1562.  
  1563.          (DO ((variable initial next)) exit-clause body)
  1564.            <=>
  1565.          (LABELS (((LOOP variable)
  1566.                    (COND exit-clause
  1567.                          (ELSE body
  1568.                                (LOOP next)))))
  1569.            (LOOP initial))
  1570.                                      -21-
  1571.  
  1572.  
  1573. (ITERATE variable specs . body) -> value-of-body                   Special form
  1574.  
  1575.      Another iteration construct.  Specs has the form
  1576.  
  1577.          ((arg  val ) (arg  val ) ... (arg  val ))
  1578.               1    1      2    2          n    n
  1579.      The  variable  is  bound  to a local procedure whose formal parameters are
  1580.      arg  arg  ... arg .  The procedure is  initially  invoked  with  the  vals
  1581.         1    2        n
  1582.      bound to the corresponding args.
  1583.  
  1584.      ITERATE  is  more  flexible  than  DO.    It  is useful in loops where the
  1585.      terminating condition occurs in the middle of the body  of  the  loop,  or
  1586.      where there is more than one terminating condition, or where the iteration
  1587.      may occur in several places.
  1588.  
  1589.      For  example,  consider  the  following  example  (from [STEELE78REV]),  a
  1590.      procedure to sort a list of trees into atoms and lists:
  1591.  
  1592.          (DEFINE (COLLATE X)
  1593.            (ITERATE COL ((Z X) (ATOMS '()) (LISTS '()))
  1594.              (COND ((NULL? Z)
  1595.                     (LIST ATOMS LISTS))
  1596.                    ((ATOM? (CAR Z))
  1597.                     (COL (CDR Z) (CONS (CAR Z) ATOMS) LISTS))
  1598.                    (ELSE
  1599.                     (COL (CDR Z) ATOMS (CONS (CAR Z) LISTS))))))
  1600.  
  1601.      A  rough  analogy ITERATE : LABELS :: LET : LAMBDA holds.  ITERATE expands
  1602.      trivially into LABELS, but may be more convenient than LABELS for the same
  1603.      reason   that   a   LET   form   may  be  preferable  than  a  call  to  a
  1604.      LAMBDA-expression.
  1605.  
  1606.          (ITERATE variable ((arg  val ) (arg  val ) ... (arg  val )) . body
  1607.                                 1    1      2    2          n    n
  1608.            <=>
  1609.          (LABELS (((variable arg  arg  ... arg ) . body)) (variable val  va
  1610.                                 1    2        n                        1   
  1611.  
  1612. 5.3. Procedure application
  1613.  
  1614. The only operation which all procedures support is  invocation.    All  initial
  1615. system  routines,  like  CAR,  LIST,  and  EQ?, are procedures.  Procedures are
  1616. usually created by evaluating LAMBDA- or DEFINE-forms.
  1617.  
  1618. The standard way to apply a procedure to arguments is with a  call  expression.
  1619. Calls are described on page 3.
  1620. (PROCEDURE? object) -> boolean                                   Type predicate
  1621.  
  1622.      Returns true if object is a procedure, i.e., if it may be called.
  1623.  
  1624.                                      -22-
  1625.  
  1626.  
  1627. (APPLY procedure . objects) -> object                                          
  1628.  
  1629.      APPLY applies a procedure to a list of arguments.
  1630.  
  1631.      The sequence of object arguments should have the form
  1632.  
  1633.          arg  arg  ... arg  arglist
  1634.             1    2        n
  1635.      where  n  may be 0.  The procedure is called with arg , arg , etc., as the
  1636.                                                           1     2
  1637.      first n arguments, and the members of arglist as final arguments.
  1638.  
  1639.          (APPLY CONS '(1 2))          =>  (1 . 2)
  1640.          (APPLY CONS 1 '(2))          =>  (1 . 2)
  1641.          (APPLY CONS 1 2 '())         =>  (1 . 2)
  1642.          (APPLY LIST 1 2 3 '(4 5 6))  =>  (1 2 3 4 5 6)
  1643.  
  1644.  
  1645. 5.4. Sequencing
  1646.  
  1647. (BLOCK . body) -> value-of-body                                    Special form
  1648.  
  1649.      Body is a non-empty  sequence  of  expressions.    These  expressions  are
  1650.      evaluated  in  order  from left to right.  The BLOCK-expression yields the
  1651.      value of the last expression.
  1652.  
  1653.      Because their values are ignored, expressions  other  than  the  last  are
  1654.      useful only for side-effects they may cause.
  1655.  
  1656.      Since  the  bodies  of  most special forms are implicitly blocks, BLOCK is
  1657.      useful only in places where syntactically a single expression  is  needed,
  1658.      but some sequencing is required.
  1659.  
  1660.  
  1661. (BLOCK0 first-form . body) -> value-of-first-form                  Special form
  1662.  
  1663.      The  first-form  is  evaluated,  then  the  expressions  in  the  body are
  1664.      evaluated.  The BLOCK0-expression yields first-form's value.
  1665.  
  1666.  
  1667. 5.5. Non-local exits
  1668.  
  1669. (CATCH variable . body) -> value-of-body                           Special form    X5
  1670.  
  1671.      CATCH provides a structured, non-local exit facility similar to  PROG  and
  1672.      RETURN  (without GO), or CATCH and THROW, in other Lisps.  The variable is
  1673.      bound to an escape procedure of one argument.  If the escape procedure  is
  1674.      called  as  a  result  of evaluating body, then the argument to the escape
  1675.      procedure is returned as the value of the CATCH-expression.  If the escape
  1676.      procedure is not called, then CATCH returns whatever body returns.  A call
  1677.      to an escape procedure is called a throw.
  1678.  
  1679.      In the following example, the call to LIST never happens, because  one  of
  1680.      its subforms performs a throw.
  1681.  
  1682.          (CATCH X (LIST 1 (X 2) 3))  =>  2
  1683.  
  1684.                                      -23-
  1685.  
  1686.  
  1687.      T's  CATCH is a restriction of SCHEME's.  Escape procedures are only valid
  1688.      within the dynamic extent of the CATCH-expression; the CATCH can  yield  a
  1689.      value at most once.  Escape procedures should not be returned "upwards."
  1690.  
  1691.      A  throw  may  cause  side-effects if the dynamic state in effect when the
  1692.      escape procedure is called differs from that in effect when evaluation  of
  1693.      its  corresponding  CATCH-expression began.  In this case the throw undoes
  1694.      the effects of BIND forms, and must perform cleanup  action  requested  by
  1695.      UNWIND-PROTECT forms, in the process of "unwinding" the evaluation context
  1696.      from that of the throw to  that  of  the  CATCH.    See  section  6.3  for
  1697.      descriptions of BIND and UNWIND-PROTECT.
  1698.  
  1699.  
  1700. 5.6. Lazy evaluation
  1701.  
  1702. Delays provide a general mechanism for delayed (lazy) evaluation, also known as
  1703. "call-by-need".
  1704. (DELAY expression) -> delay                                        Special form
  1705.  
  1706.      Returns a delay of the expression.  The  computation  of  the  expression,
  1707.      which  happens  at most once, is delayed until its value is requested with
  1708.      FORCE.
  1709.  
  1710.          (DEFINE (INF-LIST-OF-INTEGERS N)
  1711.            (CONS N (DELAY (INF-LIST-OF-INTEGERS (1+ N)))))
  1712.          (HEAD (TAIL (TAIL (INF-LIST-OF-INTEGERS 1))))  =>  3
  1713.  
  1714.          (DEFINE HEAD CAR)
  1715.          (DEFINE (TAIL OBJ) (FORCE (CDR OBJ)))
  1716.  
  1717.      The behavior of  DELAY  and  FORCE  can  be  described  by  the  following
  1718.      hypothetical implementation:
  1719.  
  1720.          (DEFINE-SYNTAX (DELAY EXP)
  1721.            `(MAKE-DELAYED-OBJECT (LAMBDA () ,EXP)))
  1722.  
  1723.          (DEFINE (MAKE-DELAYED-OBJECT THUNK)
  1724.            (LET ((FORCED-YET? NIL)
  1725.                  (FORCED-VALUE NIL))
  1726.              (OBJECT NIL
  1727.                      ((FORCE SELF)
  1728.                       (COND ((NOT FORCED-YET?)
  1729.                              (SET FORCED-VALUE (THUNK))
  1730.                              (SET FORCED-YET? T)))
  1731.                       FORCED-VALUE))))
  1732.  
  1733.          (DEFINE-OPERATION (FORCE OBJ)
  1734.            OBJ)
  1735.  
  1736.  
  1737. (FORCE delay) -> object                                                        
  1738.  
  1739.      Forces  the computation of the delay's value.  If FORCE has not previously
  1740.      been  applied  to  the  delay,  then  the  expression  in   the   original
  1741.      DELAY-expression  which  created  delay  (see above) is evaluated, and its
  1742.      value is returned.  If FORCE has previously been  applied  to  the  delay,
  1743.      then the value previously computed is returned.
  1744.  
  1745.      If FORCE is applied to a non-delay, then it simply returns its argument.
  1746.  
  1747.                                      -24-
  1748.  
  1749.  
  1750. Chapter 6                                                          Side effects
  1751.  
  1752.  
  1753. A  side-effect is a change in the state of a running T system, such as a change
  1754. in the value stored in some location, or an effect on the outside world.
  1755.  
  1756. Many useful programs can be written which make no  use  of  side-effects.    In
  1757. principle,  side-effects  other  than  those  controlling the outside world are
  1758. unnecessary.  However, side effects,  when  used  carefully,  can  be  used  to
  1759. promote program modularity and readability.  In addition, they may be necessary
  1760. in a T implementation to obtain efficient program execution.
  1761.  
  1762. 6.1. Assignment
  1763.  
  1764. T provides several special forms which perform  assignment  to  locations.    A
  1765. location is a place in which a value may be stored, for example, a variable, or
  1766. the car of a list, or a component of a structure.  Locations  are  not  objects
  1767. per  se,  although  references  to  them  may  be  obtained  through the use of
  1768. locatives.
  1769. (SET location new-value) -> new-value                              Special form    X6
  1770.  
  1771.      SET is  a  generalized  assignment  operator.    It  alters  the  location
  1772.      specified  by location to hold new-value.  The value of any SET-expression
  1773.      is the new-value thus stored.
  1774.  
  1775.      If location is  a  symbol,  then  it  names  a  variable  which  has  been
  1776.      previously  bound  by a LAMBDA or an LSET (or indirectly by any form which
  1777.      does LAMBDA-binding, such as LET), whose value is to be altered.
  1778.  
  1779.          (SET X (LIST 1 2 3))  =>  (1 2 3)
  1780.          X                     =>  (1 2 3)
  1781.  
  1782.      Location may also have the syntax of a call to an access-type procedure or
  1783.      operation such as CAR.  (In this manual, these are marked as Settable.)
  1784.  
  1785.          (SET (CAR X) 'A)  =>  A
  1786.          X                 =>  (A 2 3)
  1787.  
  1788.          (SET (proc arg  ... arg ) value)  <=>  ((SETTER proc) arg  ... arg  value)
  1789.                        1        n                                 1        n
  1790.  
  1791. (SETTER procedure) -> procedure                                       Operation
  1792.  
  1793.      Given  an  access  routine,  SETTER  returns  a  corresponding  alteration
  1794.      routine.  (SETTER CAR), for example, evaluates to  a  primitive  procedure
  1795.      that  takes  two arguments, a list whose car is to be changed, and a value
  1796.      to store in the car of the list.
  1797.  
  1798.      See also DEFINE-SETTABLE-OPERATION, page 33.
  1799.  
  1800.  
  1801. (SWAP location new-value) -> object                                Special form
  1802.  
  1803.      This behaves the same as SET, except that the value returned  is  the  old
  1804.      value  found  in  location,  rather  than the new-value.  For example, the
  1805.      following expression exchanges the values of the variables X and Y:
  1806.  
  1807.          (SET X (SWAP Y X))
  1808.  
  1809.                                      -25-
  1810.  
  1811.  
  1812. (EXCHANGE location1 location2) -> undefined                        Special form
  1813.  
  1814.      Exchanges the values in the two locations.
  1815.  
  1816.  
  1817. (MODIFY location procedure) -> object                              Special form    X6
  1818.  
  1819.      Stores a value in the location which is obtained by applying procedure  to
  1820.      the old value in location.
  1821.  
  1822.          (MODIFY location 1+)  <=>  (INCREMENT location)
  1823.  
  1824.  
  1825. (MODIFY-LOCATION location continuation) -> object                  Special form
  1826.  
  1827.      Calls  continuation, which should be a procedure of two arguments, passing
  1828.      it an access procedure  of  no  arguments,  which  fetches  the  value  in
  1829.      location;  and an update procedure of one argument, which will store a new
  1830.      value in location.
  1831.  
  1832.      MODIFY-LOCATION's purpose is to ensure that any subforms of the  form  for
  1833.      location are evaluated only once.  For example,
  1834.  
  1835.          (INCREMENT (CAR (HACK))
  1836.            <=>
  1837.          (MODIFY-LOCATION (CAR (HACK))
  1838.                           (LAMBDA (FETCH STORE) (STORE (+ (FETCH) 1))))
  1839.  
  1840.      In  this  expression,  (HACK)  will be evaluated only once, whereas in the
  1841.      following naive expansion
  1842.  
  1843.          (SET (CAR (HACK)) (+ (CAR (HACK)) 1))
  1844.  
  1845.      it  is  evaluated  twice,  which  is  presumably  neither  necessary   nor
  1846.      desirable.    The  expansion  of  MODIFY-LOCATION  forms  introduces extra
  1847.      temporary variables, as needed, to account for this.
  1848.  
  1849.      Although awkward when written directly, MODIFY-LOCATION is useful in macro
  1850.      expansions.   MODIFY-LOCATION is the common special form in terms of which
  1851.      other  "modification"  forms  such  as  PUSH,   MODIFY,   and   SWAP   are
  1852.      implementeded as macros.
  1853.  
  1854.      For  example, one might define a DOUBLE macro, which multiplies by two the
  1855.      value in a location, as follows:
  1856.  
  1857.          (DEFINE-SYNTAX (DOUBLE FORM)
  1858.            `(MODIFY-LOCATION
  1859.               ,FORM
  1860.               (LAMBDA (FETCH STORE) (STORE (* (FETCH) 2)))))
  1861.  
  1862.          (DOUBLE (CAR (HACK)))
  1863.  
  1864.                                      -26-
  1865.  
  1866.  
  1867. 6.2. Locatives
  1868.  
  1869. Locatives in T are similar to the pointers or references of languages like C or
  1870. Algol 68.
  1871.  
  1872. Locatives  are  obtained  by evaluating LOCATIVE-expressions.  The value in the
  1873. location they refer to may be fetched using the CONTENTS operation, and  stored
  1874. using SET.
  1875.  
  1876. Objects  which  act  as  locatives may be created using OBJECT, as long as they
  1877. handle the CONTENTS and (SETTER CONTENTS) operations appropriately, and  handle
  1878. LOCATIVE? by returning true.
  1879. (LOCATIVE location) -> locative                                    Special form
  1880.  
  1881.      Returns  a  locative  which  accesses  the location specified by location.
  1882.      Location receives similar treatment to the location position  in  the  SET
  1883.      special  form;  it  may  refer  to a variable, or to a "field" within some
  1884.      mutable structure, for example the car of a pair.
  1885.  
  1886.      The following equivalence approximates the behavior of LOCATIVE:
  1887.  
  1888.          (LOCATIVE location)
  1889.            <=>
  1890.          (OBJECT NIL
  1891.                  ((CONTENTS SELF) location)
  1892.                  (((SETTER CONTENTS) SELF VALUE) (SET location VALUE))
  1893.                  ((LOCATIVE? SELF) T))
  1894.  
  1895.      This is accurate if location is a variable, but  if  it  is  a  call,  the
  1896.      subforms  of  the  call  are  evaluated  when  the  LOCATIVE-expression is
  1897.      evaluated, not when the contents  of  the  locative  are  required.    For
  1898.      example,
  1899.  
  1900.          (LOCATIVE (FOO (BAR BAZ)))
  1901.            <=>
  1902.          (LET ((TEMP1 FOO)
  1903.                (TEMP2 (BAR BAZ)))
  1904.            (OBJECT NIL
  1905.                    ((CONTENTS SELF) (TEMP1 TEMP2))
  1906.                    (((SETTER CONTENTS) SELF VALUE) (SET (TEMP1 TEMP2) VALUE
  1907.                    ((LOCATIVE? SELF) T)))
  1908.  
  1909.  
  1910. (CONTENTS locative) -> object                                Settable operation
  1911.  
  1912.      Dereferences (indirects through) the locative.
  1913.  
  1914.          (LSET Z (LIST 'A 'B))                   =>  (A B)
  1915.          (CONTENTS (LOCATIVE (CAR Z)))           =>  A
  1916.          (SET (CONTENTS (LOCATIVE (CAR Z))) 'C)  =>  C
  1917.          Z                                       =>  (C B)
  1918.  
  1919.          (CONTENTS (LOCATIVE location))  <=>  location
  1920.          (SET (CONTENTS (LOCATIVE location)) value  <=>  (SET location valu
  1921.  
  1922.  
  1923. (LOCATIVE? object) -> boolean                          Type predicate operation
  1924.  
  1925.      Returns true if object is a locative.
  1926.  
  1927.                                      -27-
  1928.  
  1929.  
  1930. 6.3. Dynamic state
  1931.  
  1932. (BIND specs . body) -> value-of-body                               Special form
  1933.  
  1934.      BIND implements dynamic binding.  Syntactically, it is similar to LET, but
  1935.      semantically it is completely different.  BIND operates by doing temporary
  1936.      assignments to locations, for example, to bound variables.  Unlike LET, it
  1937.      does not introduce a new lexical binding contour.
  1938.  
  1939.      Note that the use of the term bind in this context is unrelated to its use
  1940.      elsewhere (for example, at the beginning of chapter 4.1).
  1941.  
  1942.      Each spec should have the syntax
  1943.  
  1944.          (location value)
  1945.  
  1946.      The  value  in  each  location  is  obtained  and saved.  Each location is
  1947.      assigned the value, as with SET.  The body expressions are  evaluated  and
  1948.      the  value of the last is saved.  The locations are then restored to their
  1949.      original saved values.  The BIND-expression finally yields the saved value
  1950.      of the body.
  1951.  
  1952.          (BIND ((location value)) . body)
  1953.      is therefore similar to
  1954.  
  1955.          (LET ((SAVED-VALUE location))
  1956.            (SET location value)
  1957.            (BLOCK0 (BLOCK . body)
  1958.                    (SET location SAVED-VALUE)))
  1959.  
  1960.      or
  1961.  
  1962.          (LET ((SAVED-VALUE location))
  1963.            (SET location value)
  1964.            (UNWIND-PROTECT (BLOCK . body)
  1965.                            (SET location SAVED-VALUE)))
  1966.  
  1967.      Examples:
  1968.  
  1969.          (LSET A 1)
  1970.          (DEFINE (F) (+ A 1))
  1971.          (F)                   =>  2
  1972.          (LET  ((A 10)) (F))   =>  2
  1973.          (BIND ((A 10)) (F))   =>  11
  1974.  
  1975.          (LSET X (LIST 1 2 3))
  1976.          (BIND (((CAR X) 10))
  1977.            (LSET Y (COPY-LIST X)))
  1978.          X  =>  (1 2 3)
  1979.          Y  =>  (10 2 3)
  1980.  
  1981.      The  values  in  the  locations  are restored, even if a throw out of body
  1982.      occurs (see CATCH, page 23).  For example:
  1983.  
  1984.          (LET ((A 10))
  1985.            (CATCH EP (BIND ((A 20)) (EP NIL)))
  1986.            A)
  1987.            =>  10
  1988.  
  1989.      Any location in a BIND-form  which  is  a  variable  name  should  name  a
  1990.      variable  which has been previously bound using, for example, LSET or LET.
  1991.  
  1992.                                      -28-
  1993.  
  1994.  
  1995. (UNWIND-PROTECT form . unwind-forms) -> value-of-form              Special form
  1996.  
  1997.      UNWIND-PROTECT behaves nearly the same as BLOCK0:  the form is  evaluated,
  1998.      and   the  value  is  saved;  the  unwind-forms  are  evaluated;  and  the
  1999.      UNWIND-PROTECT-expression yields the (saved)  value  of  form.    However,
  2000.      unlike  BLOCK0,  UNWIND-PROTECT  guarantees  that the unwind-forms will be
  2001.      evaluated, even if a throw occurs during the evaluation of form.
  2002.  
  2003.      In the following example, the motor will be  stopped  even  if  DRILL-HOLE
  2004.      attempts to throw out of the UNWIND-PROTECT.
  2005.  
  2006.          (UNWIND-PROTECT (BLOCK (START-MOTOR)
  2007.                                 (DRILL-HOLE))
  2008.                          (STOP-MOTOR))
  2009.  
  2010.      A  throw  (see  page 23)  out  of the BLOCK -- for example, as a result of
  2011.      calling DRILL-HOLE,  will  evaluate  the  exit  form  (STOP-MOTOR)  before
  2012.      control finally returns to its corresponding CATCH.
  2013.  
  2014.      It is an error to throw out of the unwind forms of an UNWIND-PROTECT.
  2015.  
  2016.                                      -29-
  2017.  
  2018.  
  2019. Chapter 7                                                            Operations
  2020.  
  2021.  
  2022. T  provides  a simple mechanism for programming in what has come to be known as
  2023. the object-oriented  style  of  programming.    Object-oriented  style  may  be
  2024. contrasted  to  what  will here be called procedural style.  In object-oriented
  2025. programming, programs are organized by giving  the  behavior  of  objects  when
  2026. various  operations  are applied to them, whereas in procedural style, programs
  2027. are organized by giving the behavior of  procedures  when  applied  to  various
  2028. kinds of objects.  These styles are equivalent in terms of computational power,
  2029. but each offers different advantages in terms of readability and modularity.
  2030.  
  2031. T supports the object-oriented style with a special kind of procedure known  as
  2032. an  operation,  and with forms which permit one to create objects which exhibit
  2033. certain behavior when a given operation is applied to them.
  2034.  
  2035. When an operation is called, the following sequence of events occurs:
  2036.  
  2037.    - A handler is obtained for the object which was the operation's  first
  2038.      argument.    (Operations  must  always  be  called  with at least one
  2039.      argument.)
  2040.  
  2041.    - The operation asks the handler for a method  which  will  handle  the
  2042.      operation for the object.
  2043.  
  2044.    - The handler either provides a method, or it indicates that the object
  2045.      is not prepared to handle the operation.
  2046.  
  2047.    - If the handler provided a method, the method is  invoked.    If  not,
  2048.      then  the  operation's  default  method,  if any, is invoked.  If the
  2049.      operation has no default method, then the effect of the call  to  the
  2050.      operation   is  undefined  (and  presumably  an  error  condition  is
  2051.      signalled).
  2052.  
  2053. In this way, an object's handler may determine  how  the  operation  is  to  be
  2054. performed  for  the object -- that is, which particular method is to be invoked
  2055. as a result of invoking the operation.
  2056.  
  2057. Handlers map operations to methods.  Many objects may have the same handler, or
  2058. a  handler  may be idiosyncratic to a particular object.  However, every object
  2059. has a handler, so all objects participate in  the  generic  operation  dispatch
  2060. protocol.
  2061.  
  2062. 7.1. Fundamental forms
  2063.  
  2064. The  basis  of  the  generic operation system consists of the two special forms
  2065. OBJECT  and  OPERATION.    OBJECT-expressions  create  objects  which   respond
  2066. appropriately  to  generic  operations,  and  OPERATION-expressions evaluate to
  2067. operations.
  2068.  
  2069.                                      -30-
  2070.  
  2071.  
  2072. (OBJECT procedure . method-clauses) -> object                      Special form
  2073.  
  2074.      An OBJECT-expression yields an object which is prepared to handle  generic
  2075.      operations according to the method-clauses.  In the following description,
  2076.      "the object" refers to the value of a given OBJECT-expression.
  2077.  
  2078.      Each method-clause should be of the form
  2079.  
  2080.          ((operation . variables) . body)
  2081.  
  2082.      Operation is an evaluated position, and  is  typically  a  variable  which
  2083.      evaluates  to  an  operation,  although it may be any expression.  When an
  2084.      operation  is  called  with  the  object  as  its  first   argument,   the
  2085.      operation-expressions are evaluated, and if one yields the operation being
  2086.      applied to the object, the corresponding method-clause is selected.    The
  2087.      operation  is  then performed according to the selected method-clause: the
  2088.      clause's variables are bound to the arguments to the  operation,  and  its
  2089.      body, an implicit block, is evaluated.
  2090.  
  2091.          (DEFINE OP (OPERATION NIL))
  2092.          (OP (OBJECT NIL ((OP SELF) 34)))      =>  34
  2093.          (OP (OBJECT NIL ((OP SELF X) X)) 55)  =>  55
  2094.  
  2095.      Procedure  may  be  any  expression,  and  is  evaluated  at  the time the
  2096.      OBJECT-expression is evaluated.  The object, when called, simply calls the
  2097.      value  of  the  procedure expression, passing on any arguments.  Typically
  2098.      procedure might be either a LAMBDA-expression, if  the  object  is  to  be
  2099.      callable,  or  it is NIL, which by convention means that the object is not
  2100.      intended to be called, the value of NIL being an uncallable object.
  2101.  
  2102.      In the degenerate case, where there are no method clauses, the value of
  2103.  
  2104.          (OBJECT (LAMBDA args . body))
  2105.  
  2106.      is indistinguishable from that of
  2107.  
  2108.          (LAMBDA args . body).
  2109.  
  2110.      The semantics of the OBJECT and OPERATION special forms can  be  described
  2111.      in  terms  of  hypothetical  primitive procedures *OBJECT and GET-HANDLER.
  2112.      These primitives do not actually exist in T, but are  introduced  here  as
  2113.      expository  aids.    *OBJECT  takes  two  arguments, and returns an object
  2114.      which, when called, calls the object which was *OBJECT's  first  argument,
  2115.      and  when  given  to  GET-HANDLER  returns  the object which was *OBJECT's
  2116.      second argument.  That is, *OBJECT creates a two-component record (like  a
  2117.      pair),  GET-HANDLER  extracts  one  component,  and the other component is
  2118.      called when the record is called.
  2119.  
  2120.          (GET-HANDLER (*OBJECT proc handler))  <=>  handler
  2121.          ((*OBJECT proc handler) arg ...)      <=>  (proc arg ...)
  2122.  
  2123.      In addition, GET-HANDLER is defined on all objects to return some handler,
  2124.      even  objects  not  created  by  *OBJECT  (if  indeed  there  are any such
  2125.      objects).
  2126.  
  2127.                                      -31-
  2128.  
  2129.  
  2130.      Given these primitives, the following rough equivalence holds:
  2131.  
  2132.          (OBJECT proc
  2133.                  ((op  . args ) . body )
  2134.                      1       1        1
  2135.                  ((op  . args ) . body )
  2136.                      2       2        2
  2137.                  ...
  2138.                  ((op  . args ) . body ))
  2139.                      n       n        n
  2140.            <=>
  2141.          (*OBJECT proc
  2142.                   (LAMBDA (OP)
  2143.                     (SELECT OP
  2144.                       ((op ) (LAMBDA args  . body ))
  2145.                           1              1       1
  2146.                       ((op ) (LAMBDA args  . body ))
  2147.                           2              2       2
  2148.                       ...
  2149.                       ((op ) (LAMBDA args  . body ))
  2150.                           n              n       n
  2151.                       (ELSE NIL))))
  2152.  
  2153.      The  outer  LAMBDA-expression  yields  the  object's  handler;  the  inner
  2154.      LAMBDA-expressions  yield  the methods, and the mapping from operations to
  2155.      methods is accomplished by the SELECT-expression  (see  SELECT,  page 21).
  2156.      Note  that  the  syntactic  positions  op ,  op ,  ...   op  are evaluated
  2157.                                               1     2           n
  2158.      positions, and the operation expressions are evaluated when  an  operation
  2159.      is applied to the object, not when the object is created.
  2160.  
  2161.  
  2162. (OPERATION default . method-clauses) -> operation                  Special form
  2163.  
  2164.      The  syntax  of OPERATION is the same as that of OBJECT, but its semantics
  2165.      and application are somewhat different.  An OPERATION-expression evaluates
  2166.      to  an  operation.    When called, the operation obtains a handler for its
  2167.      first argument, calls the handler to obtain a method, and then invokes the
  2168.      method.    The  default  method  for the operation is established as being
  2169.      default.
  2170.  
  2171.      As the subject of another generic operation, an  operation  is  an  object
  2172.      like any other, and in this case the operation acts just as if it had been
  2173.      created by an OBJECT-expression with the same method-clauses.  In this way
  2174.      one  can  establish  the  behavior  of  an operation when subject to other
  2175.      operations, for example SETTER.
  2176.  
  2177.      The following rough equivalence  describes  the  semantics  of  OPERATION.
  2178.      Some details have been omitted.
  2179.  
  2180.          (OPERATION default . methods)
  2181.            <=>
  2182.          (LABELS ((OP (OBJECT (LAMBDA (OBJ . ARGS)
  2183.                                 (LET ((METHOD ((GET-HANDLER OBJ) OP)))
  2184.                                   (COND (METHOD
  2185.                                          (APPLY METHOD OBJ ARGS))
  2186.                                         (ELSE
  2187.                                          (APPLY default OBJ ARGS)))))
  2188.                               . methods)))
  2189.            OP)
  2190.                                      -32-
  2191.  
  2192.  
  2193.      For example:
  2194.  
  2195.          (DEFINE OP (OPERATION (LAMBDA (OBJ) 'ZEBU)))
  2196.          (OP (OBJECT NIL ((OP SELF) 'QUAGGA)))  =>  QUAGGA
  2197.          (OP 'ELAND)                            =>  ZEBU
  2198.  
  2199.      An  operation  is  created,  and  the  variable  OP  is  bound to it.  The
  2200.      operation's default method always returns  the  symbol  ZEBU.    When  the
  2201.      operation   is   applied  to  the  value  of  the  OBJECT-expression,  the
  2202.      appropriate method is invoked, and the call to the  operation  yields  the
  2203.      symbol  QUAGGA.   When the operation is applied to an object which doesn't
  2204.      handle it -- the  symbol  ELAND  --  the  operation's  default  method  is
  2205.      invoked, so the call yields the symbol ZEBU.
  2206.  
  2207.  
  2208. (OPERATION? object) -> boolean                                   Type predicate
  2209.  
  2210.      Returns true if object is an operation.
  2211.  
  2212.  
  2213. 7.2. Defining operations
  2214.  
  2215. (DEFINE-OPERATION (variable . argument-vars) . body) -> undefined  Special form
  2216.  
  2217.      Defines  variable  to  be  an  operation.    The  syntax is intended to be
  2218.      analogous to that of DEFINE.  The operation's default method is defined by
  2219.      argument-vars and body.  If there is no body, then the operation's default
  2220.      method is undefined.  In this case,  the  argument-vars  appear  only  for
  2221.      documentary purposes.
  2222.  
  2223.          (DEFINE-OPERATION (var . args) . body)
  2224.            <=>  (DEFINE var (OPERATION (LAMBDA args . body)))
  2225.  
  2226.          (DEFINE-OPERATION (var . args))
  2227.            <=>  (DEFINE var (OPERATION UNDEFINED-EFFECT))
  2228.  
  2229.  
  2230. (DEFINE-SETTABLE-OPERATION (variable . argument-vars) . body) -> undefinedSpeci
  2231.  
  2232.      Defines  variable  to  be  an  operation,  as  with  DEFINE-OPERATION, but
  2233.      arranges for the operation's "setter" to be another operation, so that the
  2234.      operation is "settable" (see page 28).
  2235.  
  2236.          (DEFINE-SETTABLE-OPERATION (var . args) . body)
  2237.            <=>
  2238.          (DEFINE var
  2239.            (LET ((THE-SETTER (OPERATION UNDEFINED-EFFECT)))
  2240.              (OPERATION (LAMBDA args . body)
  2241.                ((SETTER SELF) THE-SETTER))))
  2242.  
  2243.                                      -33-
  2244.  
  2245.  
  2246. (DEFINE-PREDICATE variable) -> undefined                           Special form
  2247.  
  2248.      Defines variable to be an operation which, by default, returns false.
  2249.  
  2250.          (DEFINE-PREDICATE var)
  2251.            <=>
  2252.          (DEFINE-OPERATION (var OBJ) NIL)
  2253.  
  2254.      The  intent  is  that particular OBJECT-expressions contain clauses of the
  2255.      form  ((variable  SELF)  T).    This  way   the   operation   defined   by
  2256.      DEFINE-PREDICATE  may  act  as a type predicate that returns true only for
  2257.      those objects returned by such OBJECT-expressions.
  2258.  
  2259.  
  2260. 7.3. Joined objects
  2261.  
  2262. (JOIN . objects) -> joined-object                                                  X7
  2263.  
  2264.      JOIN returns an object, called  a  joined  object,  whose  behavior  is  a
  2265.      combination of the behaviors of the objects.  When an operation is applied
  2266.      to the joined object, each object in  turn  is  given  an  opportunity  to
  2267.      handle the operation; the first to handle it does so.
  2268.  
  2269.          (JOIN (OBJECT proc  method   method   ...)
  2270.                            1       11       12
  2271.                (OBJECT proc  method   method   ...))
  2272.                            2       21       22
  2273.            <=>
  2274.          (OBJECT proc  method   method   ... method   method   ...)
  2275.                      1       11       12           21       22
  2276.      Using the hypothetical primitives described earlier, JOIN could be defined
  2277.      by the following:
  2278.  
  2279.          (JOIN first second)
  2280.            <=>
  2281.          (*OBJECT first
  2282.                   (LAMBDA (OP)
  2283.                     (OR ((GET-HANDLER first) OP)
  2284.                         ((GET-HANDLER second) OP))))
  2285.  
  2286.      [In T>3, JOIN works on procedures and objects created by OBJECT, but
  2287.      does not yet work on structures or primitive objects.]
  2288.  
  2289. 7.4. Synonyms
  2290.  
  2291. Synonyms   are  objects  whose  behavior  under  generic  operations  may  vary
  2292. dynamically.
  2293. (SYNONYM expression) -> synonym                                    Special form    X7
  2294.  
  2295.      Yields a synonym for expression.   If  an  operation  is  applied  to  the
  2296.      synonym, the expression is evaluated, yielding another object to which the
  2297.      operation will then be applied.
  2298.  
  2299.      Again using the non-existent *OBJECT and GET-HANDLER primitives:
  2300.  
  2301.          (SYNONYM exp)
  2302.            <=>
  2303.          (LET ((THUNK (LAMBDA () exp)))
  2304.            (*OBJECT (LAMBDA ARGS (APPLY (THUNK) ARGS))
  2305.                     (LAMBDA (OP) ((GET-HANDLER (THUNK)) OP))))
  2306.  
  2307.          [SYNONYM has been removed from T>3.]
  2308.  
  2309.                                      -34-
  2310.  
  2311.  
  2312. 7.5. Example
  2313.  
  2314. Hypothetical implementation of CONS:
  2315.  
  2316.     (DEFINE (CONS THE-CAR THE-CDR)
  2317.       (OBJECT NIL
  2318.               ((PAIR? SELF) T)
  2319.               ((CAR SELF) THE-CAR)
  2320.               ((CDR SELF) THE-CDR)
  2321.               (((SETTER CAR) SELF NEW-CAR) (SET THE-CAR NEW-CAR))
  2322.               (((SETTER CDR) SELF NEW-CDR) (SET THE-CDR NEW-CDR))))
  2323.  
  2324.     (DEFINE-PREDICATE PAIR?)
  2325.     (DEFINE-SETTABLE-OPERATION (CAR PAIR))
  2326.     (DEFINE-SETTABLE-OPERATION (CDR PAIR))
  2327.  
  2328.                                      -35-
  2329.  
  2330.  
  2331. Chapter 8                                                               Numbers
  2332.  
  2333.  
  2334. Numbers  in  T are objects which represent real numbers.  Numbers come in three
  2335. varieties: integers, ratios, and floating point numbers.  Integers  and  ratios
  2336. are  exact  models  of  the corresponding mathematical objects.  Floating point
  2337. numbers  give  discrete  approximations  to  real  numbers  within  a   certain
  2338. implementation-dependent range.
  2339.  
  2340. As expressions, numbers are self-evaluating literals (see section 3.3).
  2341.  
  2342.     -72723460248141  => -72723460248141
  2343.     13/5             =>  13/5
  2344.     34.55            =>  34.55
  2345.  
  2346. There  may  be many different objects which all represent the same number.  The
  2347. effect of this is that EQ? may behave in  nonintuitive  ways  when  applied  to
  2348. numbers.    It  is  guaranteed  that  if  two  numbers  have different types or
  2349. different numerical values, then they are not EQ?, but two numbers that  appear
  2350. to  be  the  same  may  or may not be EQ?, even though there is no other way to
  2351. distinguish them.  Use EQUAL? or = (page 39) for comparing numbers.
  2352.  
  2353. 8.1. Predicates
  2354.  
  2355. (NUMBER? object) -> boolean                                      Type predicate
  2356.  
  2357.      Returns true if object is a number.
  2358.  
  2359.  
  2360. (RATIONAL? object) -> boolean                                    Type predicate
  2361.  
  2362.      Returns true if object is an integer or a ratio.
  2363.  
  2364.  
  2365. (INTEGER? object) -> boolean                                     Type predicate
  2366.  
  2367.      Returns true if object is an integer.
  2368.  
  2369.  
  2370. (FLOAT? object) -> boolean                                       Type predicate
  2371.  
  2372.      Returns true if object is a floating point number.
  2373.  
  2374.  
  2375. (RATIO? object) -> boolean                                       Type predicate
  2376.  
  2377.      Returns true if object is a ratio.
  2378.  
  2379.  
  2380. (ODD? integer) -> boolean                                                      
  2381.  
  2382.      Returns true if integer is odd.
  2383.  
  2384.  
  2385. (EVEN? integer) -> boolean                                                     
  2386.  
  2387.      Returns true if integer is even.
  2388.  
  2389.                                      -36-
  2390.  
  2391.  
  2392. 8.2. Arithmetic
  2393.  
  2394. (+ . numbers) -> number                                                        
  2395. (ADD . numbers) -> number
  2396.  
  2397.      Returns the sum of the numbers.
  2398.  
  2399.          (+ 10 27)    =>  37
  2400.          (+ 10 27.8)  =>  37.8
  2401.          (+)          =>  0
  2402.          (+ -35)      =>  -35
  2403.          (+ 1 2 3)    =>  6
  2404.  
  2405.  
  2406. (- n1 n2) -> number                                                            
  2407. (SUBTRACT n1 n2) -> number
  2408.  
  2409.      Returns the difference of n1 and n2.
  2410.  
  2411.  
  2412. (- n) -> number                                                                
  2413. (NEGATE n) -> number
  2414.  
  2415.      Returns the additive inverse of n.
  2416.  
  2417.  
  2418. (* . numbers) -> number                                                        
  2419. (MULTIPLY . numbers) -> number
  2420.  
  2421.      Returns the product of the numbers.
  2422.  
  2423.  
  2424. (/ n1 n2) -> number                                                            
  2425. (DIVIDE n1 n2) -> number
  2426.  
  2427.      Returns the quotient of n1 and n2.
  2428.  
  2429.          (/ 20 5)    =>  4
  2430.          (/ 5 20)    =>  1/4
  2431.          (/ 5.0 20)  =>  0.25
  2432.  
  2433.  
  2434. (QUOTIENT n1 n2) -> integer                                                         
  2435.  
  2436.      Integer division; truncates the quotient of n1 and n2 towards zero.
  2437.  
  2438.  
  2439. (REMAINDER n1 n2) -> number                                                    
  2440.  
  2441.      Returns the remainder of the division of n1 by n2, with the sign of n1.
  2442.  
  2443.           Bug: REMAINDER in Tau 2.7 does strange things if its arguments aren't
  2444.           integers.
  2445.  
  2446.                                      -37-
  2447.  
  2448.  
  2449. (MOD n1 n2) -> number                                                          
  2450.  
  2451.      Returns a number k in the range from zero, inclusive,  to  n2,  exclusive,
  2452.      such  that  k  differs  from  n1  by an integral multiple of n2.  If n1 is
  2453.      positive, this behaves like REMAINDER.
  2454.  
  2455.           Bug:  MOD  in  Tau  2.7  does  strange things if its arguments aren't
  2456.           integers.
  2457.  
  2458.  
  2459. (EXPT base exponent) -> number                                                 
  2460.  
  2461.      Returns base raised to the exponent power.  Base and exponent may  be  any
  2462.      numbers.
  2463.  
  2464.           Bug: In Tau 2.7, exponent must be an integer.
  2465.  
  2466.  
  2467. (ABS n) -> number                                                              
  2468.  
  2469.      Returns the absolute value of n.
  2470.  
  2471.  
  2472. (GCD integer1 integer2) -> integer                                             
  2473.  
  2474.      Returns the greatest common divisor of integer1 and integer2.
  2475.  
  2476.          (GCD 36 60)  =>  12
  2477.  
  2478.  
  2479. (ADD1 n) -> number                                                             
  2480. (1+ n) -> number
  2481.  
  2482.      Returns n + 1.  (See also INCREMENT, page 42.)
  2483.  
  2484.  
  2485. (SUBTRACT1 n) -> number                                                        
  2486. (-1+ n) -> number
  2487.  
  2488.      Returns n - 1.  (See also DECREMENT, page 42.)
  2489.  
  2490.  
  2491. (MIN . numbers) -> number                                                      
  2492.  
  2493.      Returns the number with the least numerical magnitude.  (There must be  at
  2494.      least one number.)
  2495.  
  2496.  
  2497. (MAX . numbers) -> number                                                      
  2498.  
  2499.      Returns  the number with the greatest numerical magnitude.  (There must be
  2500.      at least one number.)
  2501.  
  2502. (TRUNCATE number) -> number
  2503.      Truncates towards zero.
  2504.                                      -38-
  2505.  
  2506.  
  2507. 8.3. Comparison
  2508.  
  2509. (= n1 n2) -> boolean                                                           
  2510. (EQUAL? n1 n2) -> boolean
  2511.  
  2512.      Returns true if n1 is numerically equal to n2.
  2513.  
  2514.  
  2515. (< n1 n2) -> boolean                                                           
  2516. (LESS? n1 n2) -> boolean
  2517.  
  2518.      Returns true if n1 is numerically less than n2.
  2519.  
  2520.  
  2521. (> n1 n2) -> boolean                                                           
  2522. (GREATER? n1 n2) -> boolean
  2523.  
  2524.      Returns true if n1 is numerically greater than n2.
  2525.  
  2526.  
  2527. (N= n1 n2) -> boolean                                                          
  2528. (NOT-EQUAL? n1 n2) -> boolean
  2529.  
  2530.      Returns true if n1 is not numerically equal to n2.
  2531. (>= n1 n2) -> boolean                                                          
  2532. (NOT-LESS? n1 n2) -> boolean
  2533.  
  2534.      Returns true if n1 is not numerically less than n2.
  2535.  
  2536.  
  2537. (<= n1 n2) -> boolean                                                          
  2538. (NOT-GREATER? n1 n2) -> boolean
  2539.  
  2540.      Returns true if n1 is not numerically greater than n2.
  2541.  
  2542.  
  2543. 8.4. Sign predicates
  2544.  
  2545. (ZERO? n) -> boolean                                                           
  2546. (=0? n) -> boolean
  2547.  
  2548.      Returns true if n is numerically equal to zero.
  2549.  
  2550.  
  2551. (NEGATIVE? n) -> boolean                                                       
  2552. (<0? n) -> boolean
  2553.  
  2554.      Returns true if n is negative.
  2555.  
  2556.  
  2557. (POSITIVE? n) -> boolean                                                       
  2558. (>0? n) -> boolean
  2559.  
  2560.      Returns true if n is positive.
  2561.  
  2562.                                      -39-
  2563.  
  2564.  
  2565. (NOT-ZERO? n) -> boolean                                                       
  2566. (N=0? n) -> boolean
  2567.  
  2568.      Returns true if n is not numerically equal to zero.
  2569.  
  2570.  
  2571. (NOT-NEGATIVE? n) -> boolean                                                   
  2572. (>=0? n) -> boolean
  2573.  
  2574.      Returns true if n is non-negative.
  2575.  
  2576.  
  2577. (NOT-POSITIVE? n) -> boolean                                                   
  2578. (<=0? n) -> boolean
  2579.  
  2580.      Returns true if n is non-positive.
  2581.  
  2582.  
  2583. 8.5. Transcendental functions
  2584.  
  2585. (EXP float) -> float                                                           
  2586.  
  2587.                             x
  2588.      Exponential function (e ).
  2589.  
  2590.  
  2591. (LOG float) -> float                                                           
  2592.  
  2593.      Natural logarithm (log x).
  2594.                            e
  2595.  
  2596. (SQRT float) -> float                                                          
  2597.  
  2598.      Returns the square root of its argument.
  2599.  
  2600.  
  2601. (COS float) -> float                                                           
  2602.  
  2603.      Returns the cosine of its argument.
  2604.  
  2605.  
  2606. (SIN float) -> float                                                           
  2607.  
  2608.      Returns the sine of its argument.
  2609.  
  2610.  
  2611. (TAN float) -> float                                                           
  2612.  
  2613.      Returns the tangent of its argument.
  2614.  
  2615.  
  2616. (ACOS float1) -> float2                                                        
  2617.  
  2618.      Arccosine.  Returns a number whose cosine is float1.
  2619.  
  2620.  
  2621. (ASIN float1) -> float2                                                        
  2622.  
  2623.      Arcsine.  Returns a number whose sine is float1.
  2624.  
  2625.                                      -40-
  2626.  
  2627.  
  2628. (ATAN2 x y) -> float                                                           
  2629.  
  2630.      Two-argument arctangent.  This computes the  angle  between  the  positive
  2631.      x-axis  and  the  point (x, y).  For example, if (x, y) is in the first or
  2632.      third quadrant, (ATAN2 x y) returns the arctangent of y/x.
  2633.  
  2634.           Bug: ATAN2 isn't implemented in Tau 2.7.  Tau 2.7 does implement ATAN
  2635.           (arctangent), however.
  2636.  
  2637.  
  2638. 8.6. Bitwise logical operators
  2639.  
  2640.      Bug:  In  Tau  2.7,  the  routines  in this section are restricted to take
  2641.      fixnums (see page 123), not arbitrary integers.
  2642.  
  2643. (LOGAND integer1 integer2) -> integer                                          
  2644.  
  2645.      Returns the bitwise logical and of its arguments.
  2646.  
  2647.          (LOGAND 10 12)  =>  8
  2648.  
  2649.  
  2650. (LOGIOR integer1 integer2) -> integer                                          
  2651.  
  2652.      Returns the bitwise logical inclusive or of its arguments.
  2653.  
  2654.  
  2655. (LOGXOR integer1 integer2) -> integer                                          
  2656.  
  2657.      Returns the bitwise logical exclusive or of its arguments.
  2658.  
  2659.  
  2660. (LOGNOT integer) -> integer                                                    
  2661.  
  2662.      Returns the bitwise logical not of its argument.
  2663.  
  2664.  
  2665. (ASH integer amount) -> integer                                                
  2666.  
  2667.      Shifts integer to the left amount bit positions.  If amount  is  negative,
  2668.      shifts integer right by the absolute value of amount bit positions.
  2669.  
  2670.  
  2671. (BIT-FIELD integer position size) -> integer                                   
  2672.  
  2673.      Extracts  a  bit  field out of integer.  The field extracted begins at bit
  2674.      position position from the low-order bit of the integer  and  consists  of
  2675.      size bits.  The extracted field is returned as a positive integer.
  2676.  
  2677.          (BIT-FIELD 27 1 3)  =>  5
  2678.          (BIT-FIELD -1 4 5)  =>  31
  2679.  
  2680.  
  2681. (SET-BIT-FIELD integer position size value) -> integer                         
  2682.  
  2683.      Inserts  a  value  into  a  bit field of integer.  The field begins at bit
  2684.      position position from the low-order bit of the integer  and  consists  of
  2685.      size  bits.    A new integer is returned which is the same as the argument
  2686.      integer except that this field has been altered to be value.
  2687.  
  2688.          (SET-BIT-FIELD 32 1 3 5)  =>  42
  2689.  
  2690.                                      -41-
  2691.  
  2692.  
  2693. 8.7. Coercion
  2694.  
  2695. (->INTEGER number) -> integer                                                  
  2696.  
  2697.      Coerces number to an integer, truncating towards zero if necessary.
  2698.  
  2699.          (->INTEGER 17)     =>  17
  2700.          (->INTEGER 7/4)    =>  1
  2701.          (->INTEGER 17.6)   =>  17
  2702.          (->INTEGER -17.6)  =>  -17
  2703.  
  2704.  
  2705. (->FLOAT number) -> float                                                      
  2706.  
  2707.      Coerces number to a floating point number.
  2708.  
  2709.          (->FLOAT 17)    =>  17.0
  2710.          (->FLOAT 7/4)   =>  1.75
  2711.          (->FLOAT 17.6)  =>  17.6
  2712.  
  2713.  
  2714. 8.8. Assignment
  2715.  
  2716. INCREMENT and DECREMENT are assignment forms, like SET and PUSH.   See  section
  2717. 6.1 for a general discussion.
  2718. (INCREMENT location) -> number                                     Special form
  2719.  
  2720.      Adds  one to the value in location, stores the sum back into location, and
  2721.      yields the sum.
  2722.  
  2723.          (LSET L 6)
  2724.          (INCREMENT L)             =>  7
  2725.          L                         =>  7
  2726.          (LSET M (LIST 10 20 30))  =>  (10 20 30)
  2727.          (INCREMENT (CAR M))       =>  11
  2728.          M                         =>  (11 20 30)
  2729.  
  2730.          (INCREMENT location)  <=>  (MODIFY location ADD1)
  2731.  
  2732.  
  2733. (DECREMENT location) -> number                                     Special form
  2734.  
  2735.      Subtracts one from the value in location, stores the difference back  into
  2736.      location, and yields the difference.
  2737.          (DECREMENT location)  <=>  (MODIFY location SUBTRACT1)
  2738.  
  2739.                                      -42-
  2740.  
  2741.  
  2742. Chapter 9                                                                 Lists
  2743.  
  2744.  
  2745. This   section  describes  routines  available  for  creating,  examining,  and
  2746. otherwise manipulating list structure.
  2747.  
  2748. 9.1. Predicates
  2749.  
  2750. (NULL? object) -> boolean                                        Type predicate
  2751.  
  2752.      Returns true if object is the empty list (null).  Since the empty list  is
  2753.      also  used  for  the  logical  false  value,  and  non-false  objects  are
  2754.      considered to be true, it turns out that NULL? is the same as NOT.
  2755.  
  2756.  
  2757. (PAIR? object) -> boolean                                        Type predicate
  2758.  
  2759.      Returns true if object is a pair.
  2760.  
  2761.          (PAIR? '(A B C))   =>  true
  2762.          (PAIR? '(A . 15))  =>  true
  2763.          (PAIR? '())        =>  false
  2764.          (PAIR? 'FOO)       =>  false
  2765.  
  2766.  
  2767. (ATOM? object) -> boolean                                        Type predicate
  2768.  
  2769.      Returns true if object is an atom.  An atom is any  object  that  isn't  a
  2770.      pair.
  2771.  
  2772.          (ATOM? object)  <=>  (NOT (PAIR? object))
  2773.  
  2774.  
  2775. (LIST? object) -> boolean                                        Type predicate
  2776.  
  2777.      Returns true if object is either a pair or the empty list.
  2778.  
  2779.          (LIST? '(A B C))   =>  true
  2780.          (LIST? '(A . 15))  =>  true
  2781.          (LIST? '())        =>  true
  2782.          (LIST? 'FOO)       =>  false
  2783.  
  2784.  
  2785. (PROPER-LIST? object) -> boolean                                               
  2786.  
  2787.      Returns  true  if list is a properly formed list, i.e., if its last pair's
  2788.      cdr is null.
  2789.  
  2790.          (PROPER-LIST? '(A B C))    =>  true
  2791.          (PROPER-LIST? '(A B . C))  =>  false
  2792.          (PROPER-LIST? '())         =>  true
  2793.  
  2794.  
  2795. (NULL-LIST? list) -> boolean                                                   
  2796.  
  2797.      Like NULL?, but has an undefined effect (and may, for example,  signal  an
  2798.      error)  if  its  argument is not either a pair or null.  (NULL-LIST? x) is
  2799.      roughly the same as (NULL? (PROCLAIM LIST? x)).
  2800.  
  2801.                                      -43-
  2802.  
  2803.  
  2804. 9.2. Constructors
  2805.  
  2806. (CONS object1 object2) -> pair                                                 
  2807.  
  2808.      Returns a new pair whose car is object1 and whose cdr is object2.
  2809.  
  2810.          (CONS 'A '())            =>  (A)
  2811.          (CONS 'A 'B)             =>  (A . B)
  2812.          (CONS 'A '(B))           =>  (A B)
  2813.          (CONS 'A (CONS 'B '()))  =>  (A B)
  2814.          (CONS 'A (LIST 'B 'C))   =>  (A B C)
  2815.  
  2816.  
  2817. (LIST . objects) -> list                                                       
  2818.  
  2819.      Returns a new list of its arguments.
  2820.  
  2821.          (LIST)                  =>  ()
  2822.          (LIST 'A)               =>  (A)
  2823.          (LIST 'A 'B)            =>  (A B)
  2824.          (LIST 'A (LIST 'B 'C))  =>  (A (B C))
  2825.          LIST  <=>  (LAMBDA THINGS THINGS)
  2826.  
  2827.  
  2828. (CONS* . objects) -> pair                                                      
  2829.  
  2830.      CONS* is a generalized CONS.  It returns a new, possibly  improper,  list,
  2831.      by consing the initial objects onto the last object.
  2832.  
  2833.          (CONS* 1 2 3)         =>  (1 2 . 3)
  2834.          (CONS* 'A 'B '(C D))  =>  (A B C D)
  2835.          (CONS* object)        <=>  object
  2836.          (CONS* object1 object2)                                           
  2837.  
  2838.  
  2839. (COPY-LIST list) -> list                                                       
  2840.  
  2841.      Makes  a  "top-level"  copy  of  a list; that is, returns a new list whose
  2842.      elements are the same as the original.
  2843.  
  2844.          (COPY-LIST list)  <=>
  2845.            (COND ((NULL-LIST? list) '())
  2846.                  (ELSE (CONS (CAR list) (COPY-LIST (CDR list)))))
  2847.  
  2848.          (COPY-LIST list)  <=>  (MAP IDENTITY list)
  2849.  
  2850.  
  2851. 9.3. List access
  2852.  
  2853. (CAR pair) -> object                                                   Settable    X7
  2854.  
  2855.      Returns the car of the pair.  By special dispensation, (CAR  '())  =>  (),
  2856.      even though the empty list is not a pair.  [(CAR '()) is an error in T >3.]
  2857.  
  2858.  
  2859. (CDR pair) -> object                                                   Settable    X7
  2860.  
  2861.      Returns  the  cdr  of the pair.  By special dispensation, (CDR '()) => (),
  2862.      even though the empty list is not a pair.  [(CDR '()_) is an error in T>3.]
  2863.  
  2864.                                      -44-
  2865.  
  2866.  
  2867. (C...R pair) -> object                                                 Settable
  2868.  
  2869.      Compositions of CAR and CDR, up to four deep, are defined.
  2870.  
  2871.          (CADAR x)   <=>  (CAR (CDR (CAR x)))
  2872.          (CADDDR x)  <=>  (CAR (CDR (CDR (CDR x))))
  2873.  
  2874.  
  2875. (NTH list n) -> object                                                 Settable
  2876.  
  2877.                   th
  2878.      Returns the n    element  of  list.    The  first  element  (the  car)  is
  2879.      (NTH  list 0), the second element is (NTH list 1), and so on.  In general,
  2880.      list must have at least n+1 elements.
  2881.  
  2882.          (NTH '(A B) 0)  =>  A
  2883.          (NTH '(A B) 1)  =>  B
  2884.          (NTH '(A B) 2)  has an undefined effect
  2885.          (NTH '() n)     has an undefined effect for any n
  2886.  
  2887.  
  2888. (NTHCDR list n) -> list                                                Settable
  2889.  
  2890.                   th
  2891.      Returns the n   tail of list.  In general,  list  must  have  at  least  n
  2892.      tails.
  2893.  
  2894.          (NTHCDR '(A B) 0)  =>  (A B)
  2895.          (NTHCDR '(A B) 1)  =>  (B)
  2896.          (NTHCDR '(A B) 2)  =>  ()
  2897.          (NTHCDR '(A B) 3)  has an undefined effect
  2898.          (NTHCDR '() n)     has an undefined effect for any nonzero n
  2899.  
  2900.           Bug: NTHCDR doesn't handle SETTER (i.e. is not settable) in Tau 2.7.
  2901.  
  2902.  
  2903. (LAST list) -> object                                                  Settable
  2904.  
  2905.      Returns the last element of list.
  2906.  
  2907.          (LAST '(A B C))  =>  C
  2908.          (LAST list)  <=>  (CAR (LASTCDR list))
  2909.  
  2910.  
  2911. (LASTCDR list) -> pair                                                 Settable
  2912.  
  2913.      Returns the last pair in list.
  2914.  
  2915.          (LASTCDR '(A B C))    =>  (C)
  2916.          (LASTCDR '(A B . C))  =>  (B . C)
  2917.  
  2918.           Bug: LASTCDR doesn't handle SETTER (i.e. is not settable) in Tau 2.7.
  2919.  
  2920.                                      -45-
  2921.  
  2922.  
  2923. 9.4. Lists as sequences
  2924.  
  2925. (LENGTH list) -> integer                                                       
  2926.  
  2927.      Return the length of list.
  2928.  
  2929.          (LENGTH '())       =>  0
  2930.          (LENGTH '(A B C))  =>  3
  2931.  
  2932.  
  2933. (APPEND . lists) -> list                                                       
  2934.  
  2935.      Constructs  a  list  which  is  the concatenation of lists.  A new list is
  2936.      constructed, except that the result has the last non-null  argument  as  a
  2937.      tail.
  2938.  
  2939.          (APPEND '(A B C) '(D E) '(F G))  =>  (A B C D E F G)
  2940.  
  2941.  
  2942. (APPEND! . lists) -> list                                                      
  2943.  
  2944.      Destructive  version  of  APPEND.  Splices the lists together, setting the
  2945.      cdr of the last pair in the first list to the  second  list,  and  so  on.
  2946.      Returns its first non-null argument.
  2947.  
  2948.          (DEFINE L1 (LIST 'A 'B 'C))
  2949.          (DEFINE L2 (LIST 'D 'E))
  2950.          L1                =>  (A B C)
  2951.          (APPEND! L1 L2)   =>  (A B C D E)
  2952.          L1                =>  (A B C D E)
  2953.          (APPEND! '() L2)  =>  (D E)
  2954.  
  2955.  
  2956. (REVERSE list) -> list                                                         
  2957.  
  2958.      Returns a new list whose elements are those of list, in reverse order.
  2959.  
  2960.          (REVERSE '(A B C))  =>  (C B A)
  2961.  
  2962.  
  2963. (REVERSE! list) -> list                                                        
  2964.  
  2965.      This  is  a  "destructive" version of REVERSE; it allocates no storage for
  2966.      the result, but rather recycles the pairs in the source list's to form the
  2967.      result list.
  2968.  
  2969.  
  2970. (SUBLIST list start count) -> list                                             
  2971.  
  2972.      Returns a list of count elements of list, beginning with element start.
  2973.  
  2974.          (SUBLIST '(A B C D E F) 2 3)  =>  (C D E)
  2975.  
  2976.                                      -46-
  2977.  
  2978.  
  2979. 9.5. Lists as sets
  2980.  
  2981. (MEMQ? object list) -> boolean                                                 
  2982.  
  2983.      Returns true if object is an element of list.
  2984.  
  2985.          (MEMQ? 'B '(A B C))           =>  true
  2986.          (MEMQ? 'B '(A (B C) D))       =>  false
  2987.          (MEMQ? 'B '(B))               =>  true
  2988.          (MEMQ? 'B '())                =>  false
  2989.          (MEMQ? 17 '(10 17))           =>  undefined
  2990.          (MEMQ? "foo" '("foo" "bar"))  =>  undefined
  2991.          (LET ((X "foo"))
  2992.            (MEMQ? X (LIST 'B X)))      =>  true
  2993.  
  2994.  
  2995. (MEM? predicate object list) -> boolean                                        
  2996.  
  2997.      Returns true if list contains an object which is equal to object according
  2998.      to predicate, which should be an equality predicate.
  2999.  
  3000.          (MEM? = 17 '(10 17))                       =>  true
  3001.          (MEM? STRING-EQUAL? "foo" '("foo" "bar"))  =>  true
  3002.  
  3003.  
  3004. (ANY? predicate . lists) -> boolean                                            
  3005.  
  3006.      Returns true if any element of list answers true to predicate.
  3007.  
  3008.          (ANY? NUMBER? '(FOO 15 BAR))  =>  true
  3009.  
  3010.  
  3011. (EVERY? predicate . lists) -> boolean                                          
  3012.  
  3013.      Returns true if every element of list answers true to predicate.
  3014.  
  3015.          (EVERY? SYMBOL? '(A B C))  =>  true
  3016.  
  3017.  
  3018. (DELQ object list) -> list                                                     
  3019.  
  3020.      Returns a list which is the same as the argument list with all occurrences
  3021.      of object removed.
  3022.  
  3023.  
  3024. (DEL predicate object list) -> list                                            
  3025.  
  3026.      Returns  a  list which is the same as list except that all elements which,
  3027.      according to predicate, are equal to object, have been removed.  Predicate
  3028.      should be an equality predicate.  
  3029.  
  3030.          (DELQ object list)  <=>  (DEL EQ? object list)
  3031.  
  3032.  
  3033. (DELQ! object list) -> list                                                    
  3034.  
  3035.      Destructive version of DELQ.  Removes all occurrences of object from list,
  3036.      possibly altering it, and returns the new and/or modified list.
  3037.  
  3038.                                      -47-
  3039.  
  3040.  
  3041. (DEL! predicate object list) -> list                                           
  3042.  
  3043.      Destructive version of DEL.  
  3044.  
  3045.          (DELQ! object list)  <=>  (DEL! EQ? object list)
  3046.  
  3047.  
  3048. 9.6. Mapping Procedures
  3049.  
  3050. (MAP proc . lists) -> list                                                     
  3051.  
  3052.      Returns a list of the results of applying proc to successive  elements  of
  3053.                         th
  3054.      the  lists;  the  n    element of the result list is the result of calling
  3055.                   th
  3056.      proc on the n   elements of the lists.  The length of the result  list  is
  3057.      the same as the length of the shortest of the lists.
  3058.  
  3059.          (MAP (LAMBDA (X) (LIST 'A X)) '(CAT DOG))  =>  ((A CAT) (A DOG))
  3060.          (MAP + '(10 20) '(5 6))                    =>  (15 26)
  3061.          (MAP LIST '(A B) '(C D E) '(F))            =>  ((A C F))
  3062.  
  3063.  
  3064. (MAPCDR proc . lists) -> list                                                  
  3065.  
  3066.      MAPCDR  is similar to MAP, except that proc is applied to successive tails
  3067.      of the lists.
  3068.  
  3069.  
  3070. (MAP! proc list) -> list                                                       
  3071.  
  3072.      For each pair in list, applies proc to the  car  of  the  pair,  and  then
  3073.      modifies the pair so that its car is the value of the application.
  3074.  
  3075.          (DEFINE L (LIST 'CAT 'DOG))  =>  (CAT DOG)
  3076.          (MAP! (LAMBDA (X) (LIST 'A X)) L)
  3077.          L  =>  ((A CAT) (A DOG))
  3078.  
  3079.  
  3080. (WALK proc . lists) -> undefined                                               
  3081.  
  3082.      This  is  similar  to  MAP  but  the  result  is  a value of no particular
  3083.      interest.  Thus WALK  is  useful  only  for  the  side-effects  that  proc
  3084.      performs.
  3085.  
  3086.  
  3087. (WALKCDR proc . lists) -> undefined                                            
  3088.  
  3089.      This  is  similar  to  MAPCDR  but  the result is a value of no particular
  3090.      interest.
  3091.  
  3092.                                      -48-
  3093.  
  3094.  
  3095. 9.7. Lists as associations
  3096.  
  3097. (ASSQ object list) -> pair or false                                            
  3098.  
  3099.          (ASSQ object list)  <=>  (ASS EQ? object list)
  3100.  
  3101.  
  3102. (ASS predicate object list) -> pair or false                                   
  3103.  
  3104.      An association list is a list of pairs that represents  a  "lookup  table"
  3105.      where  the  car  of  each  pair matches a lookup key.  ASS and its related
  3106.      procedures search association lists by comparing (applying predicate)  the
  3107.      key  (object)  against  the car of each element of list (i.e., the caar of
  3108.      each tail).  If it finds a match, it returns that element (the car of  the
  3109.      tail).  If it finds no match, it returns false.
  3110.  
  3111.          (ASS EQ? 'B '((A 10 20) (B 30 40) (C 50 60)))  =>  (B 30 40)
  3112.          (ASS = 9 '((1 Y) (4 Y) (9 Z) (12 P)))          =>  (9 Z)
  3113.          (ASS = 10 '((1 Y) (4 Y) (9 Z) (12 P)))         =>  false
  3114.  
  3115.  
  3116. 9.8. Lists as stacks
  3117.  
  3118. PUSH  and  POP  permit a convenient syntax for the use of lists in implementing
  3119. simple stacks.  They are assignment forms, like SET and INCREMENT.  See section
  3120. 6.1 for a general discussion of assignment forms.
  3121. (PUSH location object) -> undefined                                Special form
  3122.  
  3123.      Cons  a  pair  whose  car is object and whose cdr is the value in location
  3124.      (usually a list), and store the extended list back into location.
  3125.  
  3126.          (LSET L '(34 55))  =>  (34 55)
  3127.          (PUSH L 21)
  3128.          L                  =>  (21 34 55)
  3129.          (PUSH L '(A B C))
  3130.          (PUSH (CAR L) 'D)
  3131.          L                  =>  ((D A B C) 21 34 55)
  3132.  
  3133.      In general,
  3134.  
  3135.          (PUSH location object)
  3136.            <=>  (SET location (CONS object location))
  3137.            <=>  (MODIFY location (LAMBDA (L) (CONS object L)))
  3138.  
  3139.  
  3140. (POP location) -> object                                           Special form
  3141.  
  3142.      The car of the value  in  location  (this  value  should  be  a  pair)  is
  3143.      returned.    As  a  side-effect, the cdr of the list is stored back in the
  3144.      location.
  3145.  
  3146.          L        =>  (21 34 55)
  3147.          (POP L)  =>  21
  3148.          L        =>  (34 55)
  3149.  
  3150.      In general,
  3151.          (POP location)  <=>  (BLOCK0 (CAR location) (SET location (CDR loc
  3152.                              <=>  (BLOCK0 (CAR location) (MODIFY location C
  3153.  
  3154.                                      -49-
  3155.  
  3156.                                                                                                                                                                                                                                         
  3157. Chapter 10                                                                Trees
  3158.  
  3159.  
  3160. This chapter describes procedures available for manipulating trees.   The  term
  3161. tree  is  used  in  a  technical  sense to refer to non-circular list structure
  3162. considered as tree data-structures, as contrasted with lists, which use chained
  3163. pairs  to  represent a one-dimensional sequence of objects.  Thus one might say
  3164. either that (A (B C) D) is a list of three elements, or that it is a tree  with
  3165. four (non-null) leaves.
  3166.  
  3167. Trees  are  used  to  represent programs.  The tree-manipulation procedures and
  3168. special forms are designed with this in mind.
  3169.  
  3170.                                      -50-
  3171.  
  3172.  
  3173. 10.1. Comparison
  3174.  
  3175. (EQUIV? object1 object2) -> boolean                                            
  3176.  
  3177.      EQUIV? is an equality predicate, not for comparing trees but for comparing
  3178.      leaves.
  3179.  
  3180.         - If (EQ? object1 object2), then (EQUIV? object1 object2).
  3181.  
  3182.         - If  object1  and object2 are both numbers of the same type, then
  3183.           they are EQUIV? iff they have the same  numeric  value  (see  =,
  3184.           page 39).
  3185.  
  3186.         - If object1 and object2 are both strings, then they are EQUIV? if
  3187.           they are STRING-EQUAL?  (page 62).  
  3188.  
  3189.      See also the descriptions of EQ? (page 9) and = (page 29).
  3190.  
  3191.           Bug:  In  Tau  2.7,  EQUIV?  (and  ALIKEV?)  may return false for two
  3192.           numbers which are =.  It  will  do  the  right  thing,  however,  for
  3193.                                         28
  3194.           integers which are less than 2   in magnitude.
  3195.  
  3196.  
  3197. (ALIKE? predicate tree1 tree2) -> boolean                                      
  3198.  
  3199.      Returns   true   if  tree1  and  tree2  have  the  same  shape  and  their
  3200.      corresponding leaves are equal according to predicate, which  must  be  an
  3201.      equality predicate.
  3202.  
  3203.          (ALIKE? = '(1 (2 . 8) 3) '(1 (2 . 8) 3))  =>  true
  3204.  
  3205.  
  3206. (ALIKEQ? tree1 tree2) -> boolean                                               
  3207.  
  3208.          (ALIKEQ? tree1 tree2)  <=>  (ALIKE? EQ? tree1 tree2)
  3209.  
  3210.  
  3211. (ALIKEV? tree1 tree2) -> boolean                                               
  3212.  
  3213.          (ALIKEV? tree1 tree2)  <=>  (ALIKE? EQUIV? tree1 tree2)
  3214.  
  3215.      Roughly speaking, two trees are ALIKEV? if they print the same way.
  3216.  
  3217.  
  3218. 10.2. Tree utilities
  3219.  
  3220. (SUBST predicate new old tree) -> tree                                         
  3221.  
  3222.      Returns  a result tree which is the same as the argument tree, except that
  3223.      leaves in the argument tree which, according to predicate,  are  equal  to
  3224.      old,  have  been  changed  to  be  new.    Predicate  must  be an equality
  3225.      predicate.
  3226.  
  3227.          (SUBST EQUIV? 17 13 '(10 (20 13) 30))  =>  (10 (20 17) 30)
  3228.  
  3229.      The result returned by SUBST may or may not share structure with its  tree
  3230.      argument.
  3231.  
  3232.                                      -51-
  3233.  
  3234.  
  3235. (SUBSTQ new old tree) -> tree                                                  
  3236.  
  3237.          (SUBSTQ new old tree)  <=>  (SUBST EQ? new old tree)
  3238.  
  3239.  
  3240. (SUBSTV new old tree) -> tree                                                  
  3241.  
  3242.          (SUBSTV new old tree)  <=>  (SUBST EQUIV? new old tree)
  3243.  
  3244.  
  3245. (COPY-TREE tree) -> tree                                                       
  3246.  
  3247.      Recursively make a copy of the tree.  
  3248.  
  3249.          (COPY-TREE tree)  <=>  (SUBSTQ NIL NIL tree)
  3250.  
  3251.  
  3252. (TREE-HASH tree) -> integer                                                    
  3253.  
  3254.      Compute  a hash code for tree.  The hash computed is a non-negative fixnum
  3255.      with the property that if tree1 and tree2 are ALIKEV?, then  their  hashes
  3256.      are the same.
  3257.  
  3258.  
  3259. 10.3. Destructuring
  3260.  
  3261. (DESTRUCTURE specs . body) -> value-of-body                        Special form
  3262.  
  3263.      Specs  has  the  form  ((pattern  value)  (pattern value) ...)  where each
  3264.      pattern is either an identifier (e.g., X) or a tree, all  of whoe non-null
  3265.      leaves are identifiers (e.g., ((X Y . Z) P Q)).
  3266.  
  3267.      DESTRUCTURE  is  similar to LET, and in the case that all the patterns are
  3268.      symbols, DESTRUCTURE and LET are equivalent. But DESTRUCTURE is especially
  3269.      useful  when  one wants to bind variables to the various nodes in a single
  3270.      tree   structure.      For   example,   suppose   Z    has    the    value
  3271.      (1  (2  3) ((4 5 . 6) 7)), and we want to bind A to 1, B to 2, C to (3), D
  3272.      to 6, and E to 7. We could write
  3273.  
  3274.          (LET ((A (CAR Z))
  3275.                (B (CAADR Z))
  3276.                (C (CDADR Z))
  3277.                (D (CDDAR (CADDR Z)))
  3278.                (E (CADADR (CDR Z))))
  3279.            ...)
  3280.  
  3281.      However, we could also write
  3282.  
  3283.          (DESTRUCTURE (((A (B . C) ((() () . D) E)) Z))
  3284.            ...)
  3285.  
  3286.      The ()'s notate ignored positions.
  3287.  
  3288.                                      -52-
  3289.  
  3290.  
  3291. (DESTRUCTURE* specs . body) -> value-of-body                       Special form
  3292.  
  3293.      DESTRUCTURE* is the "serial" form of DESTRUCTURE,  just  as  LET*  is  the
  3294.      "serial" form of LET.
  3295.  
  3296.          (DESTRUCTURE* ((pattern  value )
  3297.                                 1      1
  3298.                         (pattern  value )
  3299.                                 2      2
  3300.                         ...
  3301.                         (pattern  value ))
  3302.                                 n      n
  3303.            code)
  3304.            <=>
  3305.          (DESTRUCTURE ((pattern  value ))
  3306.                                1      1
  3307.            (DESTRUCTURE ((pattern  value ))
  3308.                                  1      1
  3309.             ...
  3310.               (DESTRUCTURE ((pattern  value ))
  3311.                                     n      n
  3312.                 code )...))
  3313.  
  3314.  
  3315. 10.4. Quasiquote
  3316.  
  3317. T's  quasiquote facility, inherited from the Maclisp family of Lisps, is useful
  3318. for building programs whose form is determined, but where some of the structure
  3319. is  constant and some is to be filled in.  This is especially convenient in the
  3320. definitions of macro expanders.  It is so useful that a special external syntax
  3321. is  provided  for  notating such templates.  It takes its name from the name of
  3322. the character (quasiquote, `) which introduces this special syntax.
  3323.  
  3324.  
  3325. Note that  it  behaves  like  QUOTE except one can specify that subforms of the
  3326. quasiquoted form should be evaluated.  Inside a form  that  is  preceded  by  a
  3327. quasiquote, two additional pieces of external syntax are active: comma (,), and
  3328. comma at-sign (,@); these are the ways to indicate that some subform should  be
  3329. evaluated  (i.e.,  unquoted).    A subform preceded by a comma is evaluated and
  3330. replaced by the result of the evaluation.    A  subform  preceded  by  a  comma
  3331. at-sign is evaluated and replaced by splicing in the result of the evaluation.
  3332.  
  3333. Here  are  some  simple  examples.    Note  that  the  first example shows code
  3334. equivalence, not evaluation.
  3335.  
  3336.     `(A B ,X Y)  <=>  (LIST 'A 'B X 'Y)
  3337.  
  3338.     (DEFINE X '(3))
  3339.     (CDR `(A B ,X C))    =>  (B (3) C)
  3340.     (CDR `(A B ,@X C))  =>  (B 3 C)
  3341.  
  3342.     (DEFINE-SYNTAX (REPEAT N . CODE)     ;Execute CODE N times
  3343.       `(LET ((COUNT ,N) (THUNK (LAMBDA () ,@CODE)))
  3344.          (DO ((COUNT COUNT (-1+ COUNT)))
  3345.              ((<=0? COUNT) '())
  3346.            (THUNK))))
  3347.  
  3348.                                      -53-
  3349.  
  3350.  
  3351. It is possible to nest quasiquoted forms. This is useful when  writing  complex
  3352. source-to-source transformations.
  3353.  
  3354.     (DEFINE-SYNTAX (FOO X Y)
  3355.       `(LET ((STUFF ,X))
  3356.          `((STUFF-IS ,STUFF)
  3357.            (Y-IS ,',Y))))
  3358.  
  3359.     (FOO (+ 3 5) BAZ)  =>  ((STUFF-IS 8) (Y-IS BAZ))
  3360.  
  3361. [In T>3, quasiquote works on vectors as well, thus `#(1 2 ,(+ 1 2)) -> #(1 2 3)]
  3362.  
  3363.  
  3364.                                      -54-
  3365.  
  3366.  
  3367. Chapter 11                                                           Structures    X11
  3368.  
  3369.  
  3370. A  structure  corresponds to what is called a record in some other languages: a
  3371. data structure with a fixed set of  named  fields  or  slots,  known  in  T  as
  3372. components.    For  example, one might want an "employee" structure, with slots
  3373. for the employee's name, age, and salary.  A structure, then, is  an  organized
  3374. set of locations, places to store things.
  3375.  
  3376. 11.1. Terminology
  3377.  
  3378. Every  structure has an associated an object called a structure type (sometimes
  3379. abbreviated stype, pronounced "ess type").  Structure types are created by  the
  3380. procedure MAKE-STYPE (see below) and by the special form DEFINE-STRUCTURE-TYPE
  3381.  
  3382. Given a structure type S, one can access several things of interest:
  3383.  
  3384. Constructor     a procedure that will create uninitialized structures of type S
  3385.                 (e.g., the structure for a particular employee).
  3386.  
  3387. Predicator      a procedure  (a  type  predicate)  that  returns  true  if  its
  3388.                 argument is a structure of type S.
  3389.  
  3390. Component selectors
  3391.                 procedures that access the various components of structures  of
  3392.                 type S (one selector per component).
  3393.  
  3394. Handler         the  mechanism  for  specifying how a set of generic operations
  3395.                 will behave when applied to structures of type S.
  3396.  
  3397. 11.2. Defining structure types
  3398.  
  3399. The DEFINE-STRUCTURE-TYPE macro is a convenient way to define a  new  structure
  3400. type  and  its  associated  constructor,  predicator,  and component selectors.
  3401. DEFINE-STRUCTURE-TYPE is a macro defined in terms of MAKE-STYPE and  the  other
  3402. low-level routines described in the next section.  One may want to define one's
  3403. own interface to these routines, one that initializes the components when a new
  3404. instance is constructed, for example.
  3405. (DEFINE-STRUCTURE-TYPE typename . componentnames) -> stype         Special form
  3406.  
  3407.      Creates  a  structure  type  (using  MAKE-STYPE),  and defines a number of
  3408.      variables:
  3409.  
  3410.         - typename-STYPE is defined to be the structure type.
  3411.  
  3412.         - MAKE-typename is defined to be the constructor.
  3413.  
  3414.         - typename? is defined to be the predicator.
  3415.  
  3416.         - typename-componentname is defined to be  a  component  selector,
  3417.           for each of the componentnames.
  3418.  
  3419.                                      -55-
  3420.  
  3421.  
  3422.      For example,
  3423.  
  3424.          (DEFINE-STRUCTURE-TYPE EMPLOYEE NAME AGE SALARY)
  3425.  
  3426.      defines
  3427.  
  3428.         - EMPLOYEE-STYPE,  a  variable  whose  value is the structure type
  3429.           whose name is EMPLOYEE.
  3430.  
  3431.         - (MAKE-EMPLOYEE),  a   procedure   that   creates   uninitialized
  3432.           EMPLOYEE-structures.
  3433.  
  3434.         - (EMPLOYEE? object), a type predicate.
  3435.  
  3436.         - (EMPLOYEE-NAME employee) 
  3437.           (EMPLOYEE-AGE employee) 
  3438.           (EMPLOYEE-SALARY employee), selectors that access the components
  3439.           of EMPLOYEE-structures.
  3440.  
  3441.  
  3442. 11.3. Manipulating structure types
  3443.  
  3444. (MAKE-STYPE typename componentnames) -> stype                                  
  3445.  
  3446.      Returns a new structure type.  The typename, which should be a symbol,  is
  3447.      used for printing and identification purposes only.  Componentnames should
  3448.      be a list of symbols.  The componentnames  correspond  to  the  components
  3449.      that instances of the structure will have.
  3450.  
  3451.      For example:
  3452.  
  3453.          (MAKE-STYPE 'EMPLOYEE '(NAME AGE SALARY))  =>  #{Stype EMPLOYEE}
  3454.  
  3455.      This  creates  a  structure  type, identified as EMPLOYEE, whose instances
  3456.      have components NAME, AGE, and SALARY.  The object returned,  a  structure
  3457.      type,  is  appropriate  as an argument to other routines described in this
  3458.      section.
  3459.  
  3460.  
  3461. (STYPE-ID stype) -> typename                                                   
  3462.  
  3463.      Returns the type identifier for stype.
  3464.  
  3465.  
  3466. (STYPE-CONSTRUCTOR stype) -> procedure                                         
  3467.  
  3468.      Given a structure type stype, returns the procedure which will instantiate
  3469.      (i.e., create instances of) the structure type.  The constructor procedure
  3470.      takes no arguments and creates a structure with uninitialized components.
  3471.  
  3472.      Note that the constructor procedure is created at the time  the  structure
  3473.      type is created, not at the time that STYPE-CONSTRUCTOR is called.
  3474.  
  3475.          ((STYPE-CONSTRUCTOR stype))  <=>  (COPY-STRUCTURE (STYPE-MASTER st
  3476.  
  3477.                                      -56-
  3478.  
  3479.  
  3480. (STYPE-MASTER stype) -> structure                                              
  3481.  
  3482.      Returns  the  "master  copy"  from  which  all  structures  created by the
  3483.      structure type's constructor-procedure are made.  This can  be  convenient
  3484.      for   establishing   default   values  for  components  in  newly  created
  3485.      structures.  The way to do this is by storing into  the  master  copy  the
  3486.      desired default values; these values will be copied into all new instances
  3487.      of the structure type.  For example, 
  3488.  
  3489.          (SET (EMPLOYEE-SALARY (STYPE-MASTER EMPLOYEE-STYPE)) 12000)
  3490.          (EMPLOYEE-SALARY (MAKE-EMPLOYEE))  =>  12000
  3491.  
  3492.  
  3493. (STYPE-PREDICATOR stype) -> procedure                                          
  3494.  
  3495.      Given a structure type stype, returns the  procedure  (a  type  predicate)
  3496.      which  will  predicate  membership  in the structure type.  This procedure
  3497.      takes one argument and returns true if that argument is an instance of the
  3498.      structure type.
  3499.  
  3500.      Note  that  the  predicator procedure is created at the time the structure
  3501.      type is created, not at the time that STYPE-PREDICATOR is called.
  3502.  
  3503.  
  3504. (STYPE-SELECTOR stype componentname) -> procedure                              
  3505.  
  3506.      Given a structure type stype, returns the procedure which will select  the
  3507.      component  of  the structure type's instances identified by componentname.
  3508.      The selector procedure takes one argument, which must be a structure whose
  3509.      structure  type  is  stype,  and  returns the appropriate component of the
  3510.      instance.
  3511.  
  3512.      Such selector procedures support SETTER operations, which is to  say  that
  3513.      one  may  alter  components  of structures by using SET or related special
  3514.      forms.
  3515.  
  3516.      The effect of selecting a structure component that has not been previously
  3517.      set,  or  initialized from the master structure (see STYPE-MASTER, above),
  3518.      is undefined.
  3519.  
  3520.      Note that the selector procedures are created at the  time  the  structure
  3521.      type is created, not at the time that STYPE-SELECTOR is invoked.
  3522.  
  3523.  
  3524. (STYPE-SELECTORS stype) -> list of procedures                                  
  3525.  
  3526.      Given a structure type stype, returns a list of its selector procedures.
  3527.  
  3528.  
  3529. (SELECTOR-ID selector) -> identifier                                           
  3530.  
  3531.      Given  a  selector procedure, e.g., as returned by STYPE-SELECTOR, returns
  3532.      its corresponding componentname.
  3533.  
  3534.                                      -57-
  3535.  
  3536.  
  3537. (STYPE-HANDLER stype) -> handler                                       Settable
  3538.  
  3539.      Given a structure type stype, accesses the handler to be used for  generic
  3540.      operations  applied  to  instances  of  the  structure  type.  For a newly
  3541.      created structure type, this handler handles no operations,  but  one  may
  3542.      set the handler to be any handler at all.
  3543.  
  3544.  
  3545. 11.4. Manipulating structures
  3546.  
  3547. The  primary  means  for  manipulating  structures  is  to  call their selector
  3548. procedures and their setters.  For example, in  the  context  of  the  examples
  3549. above,  if  EMPLOYEE-23  is  an  EMPLOYEE-structure,  then  EMPLOYEE-23's  NAME
  3550. component may be retrieved by evaluating 
  3551.  
  3552.     (EMPLOYEE-NAME EMPLOYEE-23)
  3553.  
  3554. and this value may be set by evaluating 
  3555.  
  3556.     (SET (EMPLOYEE-NAME EMPLOYEE-23) 'FRED)
  3557.  
  3558. This works because  the  selector  procedures  for  EMPLOYEE-STYPE  handle  the
  3559. generic  operation  called  SETTER.    Structures may also be manipulated using
  3560. other generic operations.
  3561. (STRUCTURE? object) -> boolean                                   Type predicate
  3562.  
  3563.      Returns true if object is a structure.
  3564.  
  3565.  
  3566. (COPY-STRUCTURE structure) -> structure                                        
  3567.  
  3568.      Makes a copy of structure.  The value returned is a new object of the same
  3569.      structure  type  as  structure  whose  components are the same (in the EQ?
  3570.      sense) as structure's.
  3571. (COPY-STRUCTURE! destination source) -> structure                              
  3572.  
  3573.      Copies the components of  source  into  destination,  which  is  returned.
  3574.      Source and destination must be structures of the same type.
  3575.  
  3576.                                      -59-
  3577.  
  3578.  
  3579. Chapter 12                                               Characters and strings
  3580.  
  3581.  
  3582. T  has a special data type for representing characters.  Characters are objects
  3583. which may be stored in strings  and  communicated  between  the  T  system  and
  3584. external  media such as files and terminals.  Most characters represent printed
  3585. graphics such as letters, digits, and punctuation.
  3586.  
  3587. The external syntax #\x is used for characters.   x  may  either  be  a  single
  3588. character  or  the "name" of a character.  Valid character names include SPACE,
  3589. TAB, FORM, and NEWLINE.  For example:
  3590.  
  3591.     #\b            The alphabetic character lower-case b
  3592.     #\7            The digit 7
  3593.     #\;            The special character semicolon
  3594.     #\tab          The tab character
  3595.     #\NEWLINE      The new-line character
  3596.  
  3597. Some graphic characters are also readable by name:
  3598.  
  3599.     #\LEFT-PAREN      <=>   #\(
  3600.     #\RIGHT-PAREN     <=>   #\)
  3601.     #\LEFT-BRACKET    <=>   #\[
  3602.     #\RIGHT-BRACKET   <=>   #\]
  3603.     #\LEFT-BRACE      <=>   #\{
  3604.     #\RIGHT-BRACE     <=>   #\}
  3605.     #\BACKSLASH       <=>   #\\
  3606.     #\QUOTE           <=>   #\'
  3607.     #\QUASIQUOTE      <=>   #\`
  3608.     #\DOUBLEQUOTE     <=>   #\"
  3609.     #\COMMA           <=>   #\,
  3610.     #\SEMICOLON       <=>   #\;
  3611.  
  3612. The syntax #[Ascii n] may also be used for characters,where n is the ASCII code
  3613. for the character (see section 12.9).  This is not preferred, however, since it
  3614. is less readable and less abstract than the #\ syntax.
  3615.  
  3616.     #[Ascii 65]  <=>  #\A
  3617.  
  3618. Unlike numbers, characters are uniquely instantiated.  There is only one object
  3619. which represents a given graphic or other character.
  3620.  
  3621.     (EQ? #\x #\x)  ->  true
  3622.  
  3623. Characters  and strings are self-evaluating.  There is no need to quote them to
  3624. use them as constants in programs.
  3625.  
  3626. Strings are sequences of characters.  Strings actually consist of two  distinct
  3627. components, a header and a text, which may be manipulated independently of each
  3628. other.  If one doesn't use the routines in section 12.6, one need not  even  be
  3629. aware  of  this  fact, and can treat strings as if they are similar to lists of
  3630. characters.
  3631.  
  3632.                                      -60-
  3633.  
  3634.  
  3635. Strings are notated simply by  enclosing  the  actual  sequence  of  characters
  3636. within double quote characters.  For example,
  3637.  
  3638.     "Horse"
  3639.  
  3640. notates  a  five-character  string  consisting of the characters #\H, #\o, #\r,
  3641. #\s, and #\e.  The escape character (also known as backslash: \) may be used to
  3642. include a double-quote or a backslash within a string:
  3643.  
  3644.     "The \"second\" word in this string is enclosed in double-quotes."
  3645.     "\\ This string begins with one backslash."
  3646.  
  3647. There  is  no  standard  way  to  notate  a  string  which contains non-graphic
  3648. characters (e.g. control characters).
  3649.  
  3650. Strings are not uniquely instantiated; e.g.
  3651.  
  3652.     (EQ? "Eland" "Eland")
  3653.  
  3654. may or may not yield true, depending on the implementation.
  3655.  
  3656. 12.1. Predicates
  3657.  
  3658.                                      
  3659. (CHAR? object) -> boolean                                        Type predicate
  3660.  
  3661.      Returns true if object is a character.
  3662.  
  3663.          (CHAR? #\X)  =>  true
  3664.  
  3665.  
  3666. (STRING? object) -> boolean                                      Type predicate
  3667.  
  3668.      Returns true if object is a string.
  3669.  
  3670.          (STRING? "Tapir.")  =>  true
  3671.  
  3672.  
  3673. (GRAPHIC? character) -> boolean                                                
  3674.  
  3675.      Returns true if character is either the space character  (#\SPACE)  or  it
  3676.      corresponds  to  a printed graphic such as a letter, digit, or punctuation
  3677.      mark.
  3678.  
  3679.          (GRAPHIC? #\X)        =>  true
  3680.          (GRAPHIC? #\NEWLINE)  =>  false
  3681.  
  3682.  
  3683. (WHITESPACE? character) -> boolean                                             
  3684.  
  3685.      Returns true if character is a whitespace character (blank, tab,  newline,
  3686.      carriage return, line feed, or form feed).
  3687.  
  3688.          (WHITESPACE? #\X)        =>  false
  3689.          (WHITESPACE? #\NEWLINE)  =>  true
  3690.  
  3691.  
  3692.                                      -61-
  3693.  
  3694.  
  3695. (ALPHABETIC? character) -> boolean                                             
  3696.  
  3697.      Returns  true  if  character  is  an  alphabetic  (upper  or  lower  case)
  3698.      character.
  3699.  
  3700.          (ALPHABETIC? #\y)  =>  true
  3701.          (ALPHABETIC? #\7)  =>  false
  3702.  
  3703.  
  3704. (UPPERCASE? character) -> boolean                                              
  3705.  
  3706.      Returns true if character is an upper-case letter.
  3707.  
  3708.          (UPPERCASE? #\y)      =>  false
  3709.          (UPPERCASE? #\Y)      =>  true
  3710.          (UPPERCASE? #\COMMA)  =>  false
  3711.  
  3712.  
  3713. (LOWERCASE? character) -> boolean                                              
  3714.  
  3715.      Returns true if character is a lower-case letter.
  3716.  
  3717.          (LOWERCASE? #\y)      =>  true
  3718.          (LOWERCASE? #\Y)      =>  false
  3719.          (LOWERCASE? #\COMMA)  =>  false
  3720.  
  3721.  
  3722. (DIGIT? character radix) -> boolean                                            
  3723.  
  3724.      Returns true if character is a digit with respect to the given radix.
  3725.  
  3726.          (DIGIT? #\5 10)  =>  true
  3727.          (DIGIT? #\a 10)  =>  false
  3728.          (DIGIT? #\a 16)  =>  true
  3729.  
  3730.  
  3731. 12.2. Comparison
  3732.  
  3733. (CHAR= char1 char2) -> boolean                                                 
  3734. (CHAR< char1 char2) -> boolean
  3735. (CHAR> char1 char2) -> boolean
  3736. (CHARN= char1 char2) -> boolean
  3737. (CHAR>= char1 char2) -> boolean
  3738. (CHAR<= char1 char2) -> boolean
  3739.  
  3740.      Six comparison predicates are defined for characters.   CHAR=  and  CHARN=
  3741.      are  defined  for  all  characters.   The others are defined only when the
  3742.      arguments are both upper-case letters, or both lower-case letters, or both
  3743.      digits.
  3744.  
  3745.  
  3746. (STRING-EQUAL? string1 string2) -> boolean                                     
  3747.  
  3748.      Returns true if the two strings have the same length and characters.
  3749.  
  3750.                                      -62-
  3751.  
  3752.  
  3753. 12.3. String constructors
  3754.  
  3755. (MAKE-STRING length) -> string                                                 
  3756.  
  3757.      Makes a string of null characters whose length is length.
  3758.  
  3759.  
  3760. (STRING-APPEND . strings) -> string                                            
  3761.  
  3762.      Returns a new string which is the concatenation of strings.
  3763.  
  3764.          (STRING-APPEND "llama" " and " "alpaca")  =>  "llama and alpaca"
  3765.  
  3766.  
  3767. (COPY-STRING string) -> string                                                 
  3768.  
  3769.      Returns  a  new string, with new text, whose characters and length are the
  3770.      same as those of string.
  3771.  
  3772.  
  3773. (CHAR->STRING character) -> string                                             
  3774.  
  3775.      Creates a string of length one whose single element is character.
  3776.  
  3777.          (CHAR->STRING #\B)  =>  "B"
  3778.  
  3779.  
  3780. (LIST->STRING list) -> string                                                  
  3781.  
  3782.      Converts a list of characters to a string.
  3783.  
  3784.          (LIST->STRING '(#\Z #\e #\b #\u))  =>  "Zebu"
  3785. (STRING->LIST string) -> list                                                  
  3786.  
  3787.      Converts a string to a list of characters.
  3788.  
  3789.          (STRING->LIST "Zebu")  =>  (#\Z #\e #\b #\u)
  3790.  
  3791.  
  3792. 12.4. String access
  3793.  
  3794. (STRING-LENGTH string) -> integer                                      Settable
  3795.  
  3796.      Returns string's length.  A string's length may be SET, but the new length
  3797.      must be less than or equal to the original length.
  3798.  
  3799.  
  3800. (STRING-EMPTY? string) -> boolean                                              
  3801.  
  3802.      Returns true if string is an empty string.
  3803.  
  3804.          (STRING-EMPTY? "")         =>  true
  3805.          (STRING-EMPTY? "Bharal")   =>  false
  3806.          (STRING-EMPTY? string)     <=>  (=0? (STRING-LENGTH string))
  3807.  
  3808.                                      -63-
  3809.  
  3810.  
  3811. (STRING-ELT string n) -> character                                     Settable
  3812. (NTHCHAR string n) -> character
  3813.  
  3814.                   th
  3815.      Returns the n   character in string (zero-based).
  3816.  
  3817.          (NTHCHAR "SAIGA" 2)  =>  #\I
  3818.  
  3819.  
  3820. (STRING-HEAD string) -> character                                      Settable
  3821. (CHAR string) -> character
  3822.  
  3823.      Returns first character in string.
  3824.  
  3825.  
  3826. (STRING-TAIL string) -> string                                                 
  3827. (CHDR string) -> string
  3828.  
  3829.      Returns the "tail" of string.
  3830.  
  3831.          (STRING-TAIL "Ibex.")  =>  "bex."
  3832.  
  3833.  
  3834. (STRING-NTHTAIL string n) -> string                                            
  3835. (NTHCHDR string n) -> string
  3836.  
  3837.                   th
  3838.      Returns the n   tail of string.
  3839.  
  3840.          (NTHCHDR "SAIGA" 2)  =>  "IGA"
  3841.  
  3842.  
  3843. (SUBSTRING string start count) -> string                                       
  3844.  
  3845.                                                             th
  3846.      Returns a substring of string, beginning with the start   character, for a
  3847.      length of count characters.
  3848.  
  3849.          (SUBSTRING "A small oryx" 2 5)  =>  "small"
  3850.  
  3851.  
  3852. (STRING-SLICE string start count) -> string                                    
  3853.  
  3854.                                                                              th
  3855.      Returns  a  substring  (slice)  of  string,  beginning  with  the  start  
  3856.      character, for a length of count characters.
  3857.  
  3858.          (STRING-SLICE "A small oryx" 2 5)  =>  "small"
  3859.  
  3860.      Unlike  SUBSTRING, the characters returned by STRING-SLICE are shared with
  3861.      the original string; that is, any changes to characters  in  the  original
  3862.      string  which  have  been  selected  in the substring are reflected in the
  3863.      substring, and vice versa.
  3864.  
  3865.                                      -64-
  3866.  
  3867.  
  3868. 12.5. String manipulation
  3869.  
  3870. (STRING-POSQ character string) -> integer or false                             
  3871.  
  3872.      Returns the index of the first occurrence of character in string, if it is
  3873.      there; otherwise returns false.
  3874.  
  3875.          (STRING-POSQ #\i "oribi")  =>  2
  3876.          (STRING-POSQ #\s "oribi")  =>  false
  3877.  
  3878.  
  3879. (STRING-REPLACE destination source count) -> string                            
  3880.  
  3881.      Copies  count characters from the source string to the destination string,
  3882.      destructively, and return the modified destination.
  3883.  
  3884.          (DEFINE S (COPY-STRING "The bison"))
  3885.          (STRING-REPLACE S "Any how" 3)  =>  "Any bison"
  3886.  
  3887.  
  3888. (MAP-STRING procedure string) -> string                                        
  3889.  
  3890.      Calls procedure on each character in  string,  collecting  the  successive
  3891.      return values which should be characters in a new string.
  3892.  
  3893.          (MAP-STRING CHAR-UPCASE "A grisbok")  =>  "A GRISBOK"
  3894.  
  3895.  
  3896. (MAP-STRING! procedure string) -> string                                       
  3897.  
  3898.      Calls  procedure  on  each  character in string, storing the results which
  3899.      should be characters back into string.
  3900.  
  3901.  
  3902. (WALK-STRING procedure string) -> undefined                                    
  3903.  
  3904.      Calls procedure on each character in string.
  3905.  
  3906.  
  3907. 12.6. String header manipulation
  3908.  
  3909. A string header is a structure of fixed size which contains a  pointer  into  a
  3910. string text, and a length.  A string text is a vector of characters themselves.
  3911. The string text is not itself a directly accessible object,  but  can  only  be
  3912. manipulated  via  a  string  header.  Several string headers may point into the
  3913. same text.  The term string is used to refer to a header and text considered as
  3914. a whole.
  3915. (CHOPY string) -> string                                                       
  3916.  
  3917.      Makes  a  new string header pointing to the same string text, and with the
  3918.      same length, as the header for string.
  3919.  
  3920.  
  3921. (CHOPY! destination source) -> string                                          
  3922.  
  3923.      Copies  the  header  for  the  source  string  into  the  header  for  the
  3924.      destination string, which is returned.
  3925.  
  3926.                                      -65-
  3927.  
  3928.  
  3929. (STRING-TAIL! string) -> string                                                
  3930. (CHDR! string) -> string
  3931.  
  3932.      Destructively  modifies  string's header to point to the next character in
  3933.      its text, and decrements its length.
  3934.  
  3935.          (LET ((S (COPY-STRING "String.")))
  3936.            (CHDR! S)
  3937.            S)
  3938.                  =>
  3939.          "tring."
  3940.  
  3941.  
  3942. (STRING-NTHTAIL! string n) -> string                                           
  3943. (NTHCHDR! string n) -> string
  3944.  
  3945.      Destructive version of STRING-NTHTAIL.
  3946.  
  3947.  
  3948. 12.7. Case conversion
  3949.  
  3950. (CHAR-UPCASE character) -> character                                           
  3951.  
  3952.      If  character  is  a  lower-case  character,  returns  the   corresponding
  3953.      upper-case  character.  Otherwise character, which must be a character, is
  3954.      returned.
  3955.  
  3956.  
  3957. (CHAR-DOWNCASE character) -> character                                         
  3958.  
  3959.      If  character  is  an  upper-case  character,  returns  the  corresponding
  3960.      lower-case  character.  Otherwise character, which must be a character, is
  3961.      returned.
  3962.  
  3963.  
  3964. (STRING-UPCASE string) -> string                                               
  3965.  
  3966.      Returns a copy of string with all lower-case characters converted to upper
  3967.      case.
  3968.  
  3969.          (STRING-UPCASE string)  <=>  (MAP-STRING CHAR-UPCASE string)
  3970.  
  3971.  
  3972. (STRING-DOWNCASE string) -> string                                             
  3973.  
  3974.      Returns a copy of string with all upper-case characters converted to lower
  3975.      case.
  3976.  
  3977.          (STRING-DOWNCASE string)  <=>  (MAP-STRING CHAR-DOWNCASE string)
  3978.  
  3979.  
  3980. (STRING-UPCASE! string) -> string                                              
  3981.  
  3982.      Destructive version of STRING-UPCASE.
  3983.  
  3984.          (STRING-UPCASE! string)  <=>  (MAP-STRING! CHAR-UPCASE string)
  3985.  
  3986.                                      -66-
  3987.  
  3988.  
  3989. (STRING-DOWNCASE! string) -> string                                            
  3990.  
  3991.      Destructive version of STRING-DOWNCASE.
  3992.          (STRING-DOWNCASE! string)  <=>  (MAP-STRING! CHAR-DOWNCASE string)
  3993.  
  3994.  
  3995. 12.8. Digit conversion
  3996.  
  3997. (CHAR->DIGIT character radix) -> integer                                       
  3998.  
  3999.      Returns the weight of the character when treated as a  digit.    Character
  4000.      must be a digit in the given radix.
  4001.  
  4002.          (CHAR->DIGIT #\A 16)  =>  10
  4003.  
  4004.  
  4005. (DIGIT->CHAR integer radix) -> character                                       
  4006.  
  4007.      Given  a  non-negative  integer  less  than  radix, returns a character (a
  4008.      digit) whose weight is the integer.
  4009.  
  4010.          (DIGIT->CHAR 10 16)  =>  #\A
  4011.  
  4012.  
  4013. (DIGIT character radix) -> integer or false                                    
  4014.  
  4015.      If character is a digit, returns its weight; otherwise returns false.
  4016.  
  4017.          (DIGIT #\5 10)  =>  5
  4018.  
  4019.  
  4020. 12.9. ASCII conversion
  4021.  
  4022. (CHAR->ASCII character) -> integer                                             
  4023.  
  4024.      Given a character, returns its ASCII representation as an integer.
  4025.  
  4026.  
  4027. (ASCII->CHAR integer) -> character                                             
  4028.  
  4029.      Given an integer which is the ASCII code for some character,  returns  the
  4030.      character.
  4031.  
  4032.  
  4033. NUMBER-OF-CHAR-CODES -> integer                                              
  4034.  
  4035.      The  value of NUMBER-OF-CHAR-CODES   is a number that is 1 larger than the
  4036.      largest value that will ever be returned by CHAR->ASCII.  This may be used
  4037.      to make tables which are to be indexed by ASCII codes.
  4038.  
  4039.          (DEFINE *TABLE* (MAKE-VECTOR *NUMBER-OF-CHAR-CODES*))  =>  vector
  4040.          (VSET *TABLE* (CHAR->ASCII #\F) 'COW)                  =>  COW
  4041.          (VREF *TABLE* (CHAR->ASCII #\F))                       =>  COW
  4042.  
  4043.                                      -67-
  4044.  
  4045.  
  4046. 12.10. Symbols
  4047.  
  4048. Symbols  are similar to strings, but are instantiated uniquely; only one symbol
  4049. with a given print name exists.  Symbols are used to identify variables,  among
  4050. other  things.    The  fact that they have a convenient external representation
  4051. makes them useful for many purposes.
  4052.  
  4053. Symbols may be coerced to strings and vice versa.  If two strings are equal  to
  4054. each  other  (e.g.  according to STRING-EQUAL?), then they will both convert to
  4055. the same symbol.
  4056.  
  4057.     (EQ? (STRING->SYMBOL string1) (STRING->SYMBOL string2))
  4058.  
  4059. if and only if
  4060.  
  4061.     (STRING-EQUAL? string1 string2)
  4062.  
  4063. See also sections 3.4 and 14.1.
  4064. (STRING->SYMBOL string) -> symbol                                              
  4065.  
  4066.      Returns the symbol whose print name is equal to string.
  4067.  
  4068.          (STRING->SYMBOL "COW")    =>  COW
  4069.          (STRING->SYMBOL "123")    =>  \123
  4070.          (STRING->SYMBOL "bison")  =>  \b\i\s\o\n
  4071.          (STRING->SYMBOL "")       =>  #[Symbol ""]
  4072.  
  4073.      Note that it is READ-OBJECT (page 77), not STRING->SYMBOL,  which  coerces
  4074.      alphabetic characters to upper case.
  4075.  
  4076.  
  4077. (SYMBOL->STRING symbol) -> string                                              
  4078.  
  4079.      Returns a string for which STRING->SYMBOL will return symbol.
  4080.  
  4081.          (SYMBOL->STRING 'COW)  =>  "COW"
  4082.  
  4083.  
  4084.                                      -68-
  4085.  
  4086.  
  4087. Chapter 13                                               Miscellaneous features
  4088.  
  4089.  
  4090. 13.1. Comments and declarations
  4091.  
  4092. (COMMENT . comment) -> undefined                                   Special form
  4093.  
  4094.      Does nothing and returns no value of interest.  COMMENT-expressions may be
  4095.      used to write comments in code.  (The preferred  way  to  write  comments,
  4096.      however, is with the semicolon read macro character.)
  4097.  
  4098.  
  4099. (IGNORE . variables) -> undefined                                  Special form
  4100.  
  4101.      Ordinarily,  programs  such  as compilers which manipulate source programs
  4102.      consider it to be an exceptional condition when a bound  variable  is  not
  4103.      referenced,  and  may  generate  warning  messages  when  they detect this
  4104.      condition.  IGNORE-expressions may be used to suppress such  warnings  and
  4105.      also  to  request  that  a  warning  be  issued  if  in fact there are any
  4106.      references to variables.
  4107.  
  4108.          (LAMBDA (X Y) (IGNORE X) (CAR Y))
  4109.  
  4110.  
  4111. (IGNORABLE . variables) -> undefined                               Special form
  4112.  
  4113.      IGNORABLE is like IGNORE except that  permission  is  not  given  to  give
  4114.      warnings  if  any of variables actually is referenced.  This is not useful
  4115.      for human-generated expressions, but may be useful in the expansion  of  a
  4116.      macro  invocation  where  the  macro expander may not know whether a bound
  4117.      variable in the expansion is referenced or not, and wants to declare  that
  4118.      it is all right if the variable is not referenced.
  4119.  
  4120.  
  4121. 13.2. Errors and dead ends
  4122.  
  4123. (ERROR control-string . arguments) -> object                                   
  4124.  
  4125.      Signals  an  error.    Control-string  and  arguments  should be arguments
  4126.      suitable for a call to FORMAT (page 92).  The  error  is  reported  in  an
  4127.      implementation-dependent   manner,  and  an  opportunity  is  provided  to
  4128.      possibly correct or proceed from the error.  (See section 19.1 for details
  4129.      of Tau's handling of errors.)
  4130.  
  4131.          (ERROR "cannot wash the dishes because ~A" EXCUSE-DESCRIPTION-STRI
  4132.  
  4133.  
  4134. (SYNTAX-ERROR control-string . arguments) -> object                            
  4135.  
  4136.      Similar  to ERROR, but signals a syntax error.  This should be called, for
  4137.      example,  from  within  macro  expanders  when  an   illegal   syntax   is
  4138.      encountered.
  4139.  
  4140.  
  4141. (READ-ERROR port control-string . arguments) -> object                       
  4142.  
  4143.      Similar  to  ERROR,  but signals a read error.  This should be called, for
  4144.      example,  from  within  read  macros  when  an  illegal  read  syntax   is
  4145.      encountered.
  4146.  
  4147.                                      -69-
  4148.  
  4149.  
  4150. (CHECK-ARG predicate object procedure) -> object                               
  4151.  
  4152.      Verifies  that  an  object is of a particular type.  Predicate should be a
  4153.      type predicate, and object can be any object.  If predicate, when  applied
  4154.      to object, returns false, then an error is signalled.  If it returns true,
  4155.      then the CHECK-ARG returns object.  Procedure is a  procedure  whose  name
  4156.      will be given in any message printed by the error system.
  4157.  
  4158.      The  user interface (see section 19.1) may provide a way to supply a value
  4159.      to use in place of object.  If the user attempts to correct the  error  in
  4160.      this way, then CHECK-ARG again verifies that the new value answers true to
  4161.      predicate, and returns it.
  4162.  
  4163.      For example:
  4164.  
  4165.          (DEFINE (WASH-DISH DISH)
  4166.            (LET ((DISH (CHECK-ARG DISH? DISH WASH-DISH)))
  4167.              ...))
  4168.  
  4169.  
  4170. (PROCLAIM predicate object) -> object                                          
  4171.  
  4172.      Returns object, which must answer true to predicate.  A call  to  PROCLAIM
  4173.      serves  as  a  type declaration; this may assist an optimizing compiler in
  4174.      generating efficient code.
  4175.  
  4176.          (PROCLAIM predicate object)
  4177.            <=>
  4178.          (LET ((VALUE object))
  4179.            (COND ((predicate VALUE) VALUE)
  4180.                  (ELSE (UNDEFINED-EFFECT))))
  4181.  
  4182.  
  4183. (ASSERT boolean) -> undefined                                                  
  4184.  
  4185.      Has no effect and returns an undefined value, unless boolean is false,  in
  4186.      which  case the effect is undefined (normally, this means that an error is
  4187.      signalled).
  4188.  
  4189.  
  4190. (UNDEFINED-VALUE . arguments) -> undefined                                     
  4191.  
  4192.      Has no effect and yields some undefined value.    An  implementation  will
  4193.      endeavor to return some object which, when printed or otherwise displayed,
  4194.      will show the arguments.  This feature may be  useful  in  debugging,  for
  4195.      example  in  tracking down the origin of the undefined value, if the value
  4196.      has propagated to an undesirable place.
  4197.  
  4198.  
  4199. (UNDEFINED-EFFECT . arguments) -> undefined                                    
  4200.  
  4201.      The effect of calling UNDEFINED-EFFECT is undefined.    An  implementation
  4202.      will  endeavor  to  signal  an error condition if such a call ever occurs;
  4203.      however, an optimizing compiler may make use of the fact that the  control
  4204.      path  leading  to  a  call  to  UNDEFINED-EFFECT  will never be taken in a
  4205.      correctly running program, and so in some cases may eliminate the call.
  4206.  
  4207.  
  4208.                                      -70-
  4209.  
  4210.  
  4211. 13.3. Early binding
  4212.  
  4213. (DEFINE-CONSTANT variable value) -> undefined                      Special form
  4214.  
  4215.      This is semantically identical to DEFINE, but also declares that the value
  4216.      of  the variable will not change.  This might permit a compiler to perform
  4217.      constant-folding.  Also, if the variable is defined to be a small integer,
  4218.      this  may  interact  well  with  SELECT to obtain fast numeric dispatch on
  4219.      "enumerated types."
  4220.  
  4221.  
  4222. (DEFINE-INTEGRABLE variable value) -> undefined                    Special form
  4223. (DEFINE-INTEGRABLE (variable . arguments) . body) -> undefined
  4224.  
  4225.      This is semantically identical to DEFINE, but also declares that the value
  4226.      of the variable is not expected to change.  For example, if a reference to
  4227.      the variable  is  encountered  in  functional  position  in  a  call,  its
  4228.      definition may be integrated, that is, substituted in-line.
  4229.  
  4230.           Bug: TC 1.4 will blow up on integrating a recursive procedure defined
  4231.           with DEFINE-INTEGRABLE.
  4232.  
  4233.  
  4234. 13.4. Symbol generators
  4235.  
  4236. (GENERATE-SYMBOL prefix) -> symbol                                             
  4237.  
  4238.      Each  call  to  GENERATE-SYMBOL  generates  a unique identifier.  The form
  4239.      which the new identifier's name takes is not defined, but  the  identifier
  4240.      is  guaranteed  to  be  different from any identifier created in any other
  4241.      way.  The identifier's external representation will begin with prefix.
  4242.  
  4243.  
  4244. (CONCATENATE-SYMBOL . things) -> symbol                                        
  4245.  
  4246.      Creates  a  symbol  whose  print name is obtained by appending the printed
  4247.      representations of things according to the DISPLAY operation.
  4248.  
  4249.          (CONCATENATE-SYMBOL 'FOO- "THING-" 34)  =>  FOO-THING-34
  4250.  
  4251.  
  4252. 13.5. Combinators
  4253.  
  4254. (ALWAYS value) -> procedure                                                    
  4255.  
  4256.      Returns a procedure which ignores its arguments and always returns value.
  4257.  
  4258.          (ALWAYS value) <=> (LAMBDA X (IGNORE X) value)
  4259.  
  4260.  
  4261. (IDENTITY object) -> object                                                    
  4262.  
  4263.      Identity function.  Returns its argument.
  4264.  
  4265.                                      -71-
  4266.  
  4267.  
  4268. (PROJN n) -> procedure                                                         
  4269.  
  4270.                                                         th
  4271.      Returns a procedure which returns (projects) its  n    argument,  ignoring
  4272.      any others.
  4273.  
  4274.          (PROJN 1)  <=>  (LAMBDA (A B . REST) (IGNORE A REST) B)
  4275.  
  4276.  
  4277. (PROJ0 object . rest) -> object                                                
  4278.  
  4279.                                           th
  4280.      Projection function: returns its zero   argument, ignoring the rest.
  4281.  
  4282.          PROJ0  <=>  (PROJN 0)
  4283.  
  4284.      PROJ0  is similar to BLOCK0 (page23), except that it is a procedure, not a
  4285.      special form.
  4286. (PROJ1 object0 object1 . rest) -> object1                                      
  4287.  
  4288.      Returns its second argument.
  4289.  
  4290.  
  4291. (PROJ2 object0 object1 object2 . rest) -> object2                              
  4292.  
  4293.      Returns its third argument.
  4294.  
  4295.  
  4296. (PROJ3 object0 object1 object2 object3 . rest) -> object3                      
  4297.  
  4298.      Returns its fourth argument.
  4299.  
  4300.  
  4301. (CONJOIN . predicates) -> predicate                                            
  4302.  
  4303.      Returns a predicate which  is  the  logical  conjunction  of  all  of  the
  4304.      predicates.
  4305.  
  4306.          ((CONJOIN >0? ODD?) 13)  =>  true
  4307.          ((CONJOIN >0? ODD?) 8)  =>  false
  4308.  
  4309.  
  4310. (DISJOIN . predicates) -> predicate                                            
  4311.  
  4312.      Returns  a  predicate  which  is  the  logical  disjunction  of all of the
  4313.      predicates.
  4314.  
  4315.          ((DISJOIN >0? ODD?) 13)  =>  true
  4316.          ((DISJOIN >0? ODD?) 8)  =>  true
  4317.  
  4318.  
  4319. (COMPLEMENT predicate) -> predicate                                            
  4320.  
  4321.      Returns a predicate which is the logical complement of the predicate.
  4322.  
  4323.          ATOM? <=> (COMPLEMENT PAIR?)
  4324.          ((COMPLEMENT MEMQ?) 'A '(X Y Z))  =>  true
  4325.  
  4326.                                      -72-
  4327.  
  4328.  
  4329. (COMPOSE . procedures) -> procedure                                            
  4330.  
  4331.      Returns a procedure which is the composition of the procedures.  The  last
  4332.      of  the  procedures  may  take  any number of arguments, and the resulting
  4333.      procedure  will  take  that  same  number  of  arguments;  all  the  other
  4334.      procedures must take one argument.
  4335.  
  4336.          ((COMPOSE CAR CDR) '(A B)) =>  B
  4337.          (COMPLEMENT predicate)     <=>  (COMPOSE NOT predicate)
  4338.          PROPER-LIST?               <=>  (DISJOIN NULL? (COMPOSE NULL? CDR LASTCDR))
  4339.          NTH                        <=>  (COMPOSE CAR NTHCDR)
  4340.  
  4341.  
  4342. (TRUE . arguments) -> true                                       Type predicate
  4343.  
  4344.      Ignores  its  arguments,  and  always returns true.  This may be used as a
  4345.      predicate representing the "universal type" -- the type which subsumes all
  4346.      objects.
  4347.  
  4348.  
  4349. (FALSE . arguments) -> false                                     Type predicate
  4350.  
  4351.      Ignores  its  arguments,  and always returns false.  This may be used as a
  4352.      predicate representing the "null type"  --  the  type  which  subsumes  no
  4353.      objects.
  4354.  
  4355.  
  4356. (TRUE? value) -> boolean                                         Type predicate
  4357.  
  4358.      Returns  true  if  value  is  some  true  value, false otherwise.  This is
  4359.      convenient where one wants to coerce a truth value to be a standard  truth
  4360.      value;  that  is,  TRUE?  maps  false to itself, and any true value to the
  4361.      standard true value (T).
  4362.  
  4363.          (TRUE? object)  <=>  (NOT (FALSE? object))
  4364.          (TRUE? NIL)     =>  false
  4365.          (TRUE? T)       =>  true
  4366.          (TRUE? 3)       =>  true
  4367.  
  4368.  
  4369. (BOOLEAN? object) -> boolean                                     Type predicate
  4370.  
  4371.      This returns true if object is either  the  standard  true  value  or  the
  4372.      standard false value.
  4373.  
  4374.          (BOOLEAN? NIL)  =>  true
  4375.          (BOOLEAN? T)    =>  true
  4376.          (BOOLEAN? 3)    =>  false
  4377.  
  4378.  
  4379. 13.6. Vectors
  4380.  
  4381. Vectors  can  be  thought  of  as  one-dimensional,  zero-based  arrays,  or as
  4382. fixed-length, random-access lists.  They read and print like lists with a #  in
  4383. front.     Like  lists,  but  unlike  numbers  and  strings,  vectors  are  not
  4384. self-evaluating.  To write a constant vector, quote it: '#(X Y (1 2)).
  4385. (VECTOR? object) -> boolean                                      Type predicate
  4386.  
  4387.      Returns true if object is a vector.
  4388.  
  4389.                                      -73-
  4390.  
  4391.  
  4392. (MAKE-VECTOR size) -> vector                                                   
  4393.  
  4394.      Returns a vector whose length is size.  The elements are  not  initialized
  4395.      to  any particular value.  VECTOR-FILL (see below) may be used to fill the
  4396.      vector with some useful value (such as ()).
  4397.  
  4398.  
  4399. (LIST->VECTOR list) -> vector                                                  
  4400.  
  4401.      Converts a list to a vector.
  4402.  
  4403.          (LIST->VECTOR '(A B C))  =>  #(A B C)
  4404.  
  4405.  
  4406. (VECTOR->LIST vector) -> list                                                  
  4407.  
  4408.      Converts a vector to a list.
  4409.  
  4410.          (VECTOR->LIST '#(A B C))  =>  (A B C)
  4411.  
  4412.  
  4413. (VECTOR-ELT vector n) -> object                                        Settable
  4414. (VREF vector n) -> object
  4415.  
  4416.                    th
  4417.      Accesses the n   element of vector (zero-based).
  4418.  
  4419.          (VECTOR-ELT '#(A B C) 1) =>  B
  4420.  
  4421.  
  4422. (VSET vector n object) -> object                                               
  4423.  
  4424.                th
  4425.      Sets the n   element of vector to object.
  4426.  
  4427.          (VSET vector n object) <=> (SET (VREF vector n) object)
  4428.  
  4429.  
  4430. (COPY-VECTOR vector) -> vector                                                 
  4431.  
  4432.      Makes a copy of vector.
  4433.  
  4434.  
  4435. (VECTOR-FILL vector value) -> vector                                           
  4436.  
  4437.      Sets every element of vector to value, and returns the modified vector.
  4438.  
  4439.  
  4440. (VECTOR-REPLACE target source n) -> vector                                     
  4441.  
  4442.      Sets the first n elements of target to be the same  as  the  corresponding
  4443.      elements of source, and returns the (modified) target.
  4444.  
  4445.  
  4446. (VECTOR-LENGTH vector) -> integer                                              
  4447.  
  4448.      Returns vector's length.
  4449.  
  4450.                                      -74-
  4451.  
  4452.  
  4453. (VECTOR-POS predicate object vector) -> integer or false                       
  4454.  
  4455.      Returns index of the first element x of vector such that (predicate object
  4456.      x), or false if there is no such element.
  4457.  
  4458.  
  4459. (VECTOR-POSQ object vector) -> integer or false                                
  4460.  
  4461.          (VECTOR-POSQ object vector) <=> (VECTOR-POS EQ? object vector)
  4462.  
  4463.  
  4464. (WALK-VECTOR procedure vector) -> undefined                                    
  4465.  
  4466.      Applies procedure to every element in vector.
  4467.  
  4468.  
  4469. 13.7. Pools
  4470.  
  4471. Pools give a convenient way to perform explicit storage management  in  T.  One
  4472. may  obtain  an object from a pool (popping the pool's free list, or creating a
  4473. new object if the free list is empty), and later return an object  to  a  pool.
  4474. By   managing  storage  allocation  in  this  way,  the  frequency  of  garbage
  4475. collections can be reduced.
  4476.  
  4477. All pools are emptied when a garbage collection occurs.    Garbage  collections
  4478. occur asynchronously in an implementation-dependent manner.
  4479. (MAKE-POOL identification generator) -> pool                                   
  4480.  
  4481.      Creates  a  pool.   Generator should be a procedure, and will be called by
  4482.      OBTAIN-FROM-POOL whenever the pool's free list is empty.    Identification
  4483.      is  only  for  identification  purposes,  for  example,  when  the pool is
  4484.      printed.
  4485.  
  4486.  
  4487. (OBTAIN-FROM-POOL pool) -> object                                              
  4488.  
  4489.      Obtains an object from pool.  If the pool is empty, the  pool's  generator
  4490.      is called to obtain an object, which is then returned directly.
  4491. (RETURN-TO-POOL pool object) -> undefined                                      
  4492.  
  4493.      Returns  object  to  pool.    A  future call to OBTAIN-FROM-POOL may yield
  4494.      object.
  4495.  
  4496.  
  4497. 13.8. Weak pointers
  4498.  
  4499. (OBJECT-HASH object) -> integer                                                
  4500.  
  4501.      Returns a unique numeric identifier for object.  That is,
  4502.  
  4503.          (EQ? object1 object2)
  4504.  
  4505.      if and only if
  4506.  
  4507.          (= (OBJECT-HASH object1) (OBJECT-HASH object2))
  4508.  
  4509.      Because OBJECT-HASH is invertible (see below), it can be  used  to  create
  4510.      weak  pointers  to  objects, that is, "pointers" or "references" which are
  4511.  
  4512.                                      -75-
  4513.  
  4514.  
  4515.      not strong enough to prevent an object from being reclaimed by the garbage
  4516.      collector.    This  concept of weak pointer is implemented by the integers
  4517.      returned  by  OBJECT-HASH,  which   can   be   dereferenced   by   calling
  4518.      OBJECT-UNHASH.
  4519.  
  4520.      OBJECT-HASH  is  used  by  standard  methods  for the PRINT operation when
  4521.      printing objects which have no read syntax.
  4522.  
  4523.  
  4524. (OBJECT-UNHASH integer) -> object or false                                     
  4525.  
  4526.      Returns the object whose unique identifier is integer,  or  false  if  the
  4527.      object is no longer accessible (e.g. due to garbage collection).
  4528.  
  4529.          (OBJECT-UNHASH (OBJECT-HASH object))  =>  object
  4530.  
  4531.  
  4532. Weak-sets    provide  a way to keep track of a collection of objects.  They are
  4533. sometimes known as weak sets because they behave much like sets, but an  object
  4534. in  a  weak-set    may  go  away  if  the only pointer to the object is via the
  4535. weak-set.  The garbage collector will remove such objects from weak-sets.
  4536. (MAKE-WEAK_SET identification) -> weak-set                                 
  4537.  
  4538.      Creates a new weak-set.
  4539.  
  4540.  
  4541. (ADD-TO-WEAK-SET weak-set object) -> undefined                             
  4542.  
  4543.      Adds object to weak-set.
  4544.  
  4545.  
  4546. (REMOVE-FROM-WEAK-SET weak-set object) -> undefined                        
  4547.  
  4548.      Removes object from weak-set.
  4549.  
  4550.  
  4551. (WEAK-SET->LIST weak-set) -> list                                          
  4552.  
  4553.      Returns a list of all objects currently in   weak-set.  Note that as  long
  4554.      as this list is accessible, none of the objects will be implicitly removed
  4555.      from the weak-set, because they will be accessible via this list.
  4556.  
  4557.  
  4558. (WALK-WEAK-SET weak-set procedure) -> undefined                            
  4559.  
  4560.      Calls procedure on each member of weak-set.
  4561.          (WALK-WEAK-SET weak-set procedure)
  4562.            <=>
  4563.          (WALK procedure (WEAK-SET->LIST weak-set))
  4564.  
  4565.  
  4566. [(WEAK-SET-MEMBER? object weak-set) -> boolean                        procedure
  4567.  
  4568.      returns true if object is a member of weak-set, otherwise false.
  4569.      --T>3 only.
  4570.  
  4571. (WEAK-SET-EMPTY? weak-set) -> boolean                                 procedure
  4572.  
  4573.      returns true if weak-set is empty, otherwise false.
  4574.      --T>3 only.]
  4575.                                      -76-
  4576.  
  4577.  
  4578. Chapter 14                                                               Syntax
  4579.  
  4580.  
  4581. The T standard  environment  includes  routines  which  perform  syntactic  and
  4582. semantic  analysis  of  T  programs.    There are two such subsystems within T,
  4583. corresponding to the language's two syntactic levels (see chapter  2).    These
  4584. are the reader and the compiler.
  4585.  
  4586. In an attempt to make each of these subsystems as generally useful and flexible
  4587. as possible, they are not restricted to processing the language as described in
  4588. this  manual.    Instead,  they each operate with respect to parameter clusters
  4589. known as read tables, in the case of the reader, or syntax tables, in the  case
  4590. of the compiler.
  4591.  
  4592. 14.1. The reader                                                                   X10
  4593.  
  4594. The reader is a procedure available in the standard environment as the value of
  4595. the variable READ-OBJECT.    Conceptually,  the  reader  coerces  a  port    of
  4596. characters   (external   representation)  to  a  port    of  objects  (internal
  4597. representations) via a mechanism known as parsing.
  4598. (READ-OBJECT port read-table) -> object or end-of-file                       
  4599.  
  4600.      READ-OBJECT employs the READ-CHAR (page  89)  and  UNREAD-CHAR  (page  89)
  4601.      operations  in  order  to  parse  an object according to the port's   read
  4602.      table.
  4603.  
  4604.      If the port is empty, the end-of-file token is returned.
  4605.  
  4606.      READ-OBJECT is called by the default method for the READ  operation  (page
  4607.      89),  so  the reader is usually invoked indirectly by calling READ, not by
  4608.      calling READ-OBJECT directly.  When invoked from READ, the second argument
  4609.      to  READ-OBJECT  is obtained by calling the PORT-READ-TABLE operation on
  4610.      the port.
  4611.  
  4612.  
  4613. The reader works as follows:
  4614.  
  4615. Any whitespace characters (space, tab, newline, carriage return, line feed,  or
  4616. form  feed) are read and ignored.  A non-whitespace character is obtained; call
  4617. it c.
  4618.  
  4619. If c is a read-macro character, the reader  invokes  a  specialist  routine  to
  4620. handle a syntactic construct introduced by the read-macro character.
  4621.  
  4622. If  c is not a read-macro character, then characters are read and saved until a
  4623. delimiter character is read.  A delimiter  character  is  either  a  whitespace
  4624. character,   or   one   of  the  following:  (  (left  parenthesis),  )  (right
  4625. parenthesis), [, ], {, }, or ; (semicolon).   If  the  sequence  of  characters
  4626. beginning with c and going up to but not including the delimiter is parsable as
  4627. a number, then the sequence is  converted  to  a  number,  which  is  returned.
  4628. Otherwise the sequence is converted to a symbol.
  4629.  
  4630. The  escape  character,  backslash (\), may be used within a run of constituent
  4631. characters to include unusual characters in a symbol's print  name.    In  this
  4632. case, the escaped character (i.e. the character following the escape character)
  4633. is treated as if it were a constituent character, and is not converted to upper
  4634. case if it is a lower case letter.  For example:
  4635.  
  4636.                                      -77-
  4637.  
  4638.  
  4639.     abc\;def  reads the same as  #[Symbol "ABC;DEF"]
  4640.     \a\bcdef  reads the same as  #[Symbol "abCDEF"]
  4641.     \12345    reads the same as  #[Symbol "12345"]
  4642.     \'12345   reads the same as  #[Symbol "'12345"]
  4643.  
  4644. The following are standard read-macro characters:
  4645.  
  4646. "               Doublequote:  introduces  a  string.  Characters are read until
  4647.                 another  doublequote  character  is  found   which   does   not
  4648.                 immediately  follow  a backslash (\), and a string is returned.
  4649.                 Within a string, backslash acts as an escape character, so that
  4650.                 doublequotes and backslashes may appear in strings.
  4651.  
  4652. '               Quote: 'object reads the same as (QUOTE object).
  4653.  
  4654. (               Left parenthesis: begins a list.
  4655.  
  4656. )               Right  parenthesis:  ends  a  list or vector, and is illegal in
  4657.                 other contexts.
  4658.  
  4659. `               Quasiquote: see section 10.4.
  4660.  
  4661. ,               Comma: this is part of the quasiquote syntax.
  4662.  
  4663. ;               Semicolon: introduces a  comment.    Characters  are  read  and
  4664.                 discarded  until  a  newline is encountered, at which point the
  4665.                 parsing process starts over.
  4666.  
  4667. #               Sharp-sign:  another  dispatch  to  a  specialist  routine   is
  4668.                 performed according to the character following the #.
  4669.  
  4670. Standard sharp-sign forms:
  4671.  
  4672. #\              Character syntax.  See section 12.
  4673.  
  4674. #x              Hexadecimal input.  An integer following the #x is read in base
  4675.                 16.
  4676.  
  4677. #o              Octal input.  An integer following the #o is read in base 8.
  4678.  
  4679. #b              Binary input.  An integer following the #b is read in base 2.
  4680.  
  4681. #(...)          Vector.   The  elements  of  a  vector  are  read  between  the
  4682.                 parentheses, and the vector is returned.
  4683.  
  4684. #[...]          This  syntax  is used for certain kinds of re-readable objects.
  4685.                 It  also  provides  an  alternate  syntax  for  characters  and
  4686.                 symbols.  The brackets enclose a sequence of objects; the first
  4687.                 should be a symbol which keys the type of the resulting object,
  4688.                 e.g. CHAR or SYMBOL.  For example,
  4689.  
  4690.                     #[Ascii 65]      represents the same object as  #\A
  4691.                     #[Symbol "FOO"]  represents the same object as  FOO
  4692.  
  4693.                                      -78-
  4694.  
  4695.  
  4696.                 This syntax is used by the printer when necessary, for example:
  4697.  
  4698.                     (STRING->SYMBOL "")  =>  #[Symbol ""]
  4699.                     (ASCII->CHAR 128)    =>  #[Ascii 128]
  4700.  
  4701. #{...}          This  is  the syntax used by the printer for objects which have
  4702.                 no reader syntax.  When the reader encounters the  sequence  #{
  4703.                 it signals an error.
  4704.  
  4705. 14.2. Read tables and read macros                                                  X10
  4706.  
  4707. Read  tables  package  a  number of parameters for use by programs which parse,
  4708. generate, or otherwise manipulate external syntax of programs and objects.   In
  4709. particular,  every read table contains a table which maps characters to objects
  4710. which describe their lexical properties.
  4711.  
  4712. There is a standard read table which contains the standard read syntax for  all
  4713. characters.   In order to define nonstandard read syntax, one must create a new
  4714. read table using MAKE-READ-TABLE, and arrange for READ-OBJECT to use that  read
  4715. table    instead    of    the    standard    read    table,   e.g.   by   doing
  4716. (SET (PORT-READ-TABLE ...) ...).
  4717. (MAKE-READ-TABLE read-table identification) -> new-read-table                  
  4718.  
  4719.      Creates a new read table which is a copy of  read-table.    Identification
  4720.      serves for debugging purposes only.
  4721.  
  4722.          (DEFINE *MY-READ-TABLE*
  4723.            (MAKE-READ-TABLE STANDARD-READ-TABLE '*MY-READ-TABLE*))
  4724.  
  4725.  
  4726. STANDARD-READ-TABLE -> read-table                                            
  4727.  
  4728.      The standard T read table.
  4729.  
  4730.  
  4731. VANILLA-READ-TABLE -> read-table                                             
  4732.  
  4733.      The value of VANILLA-READ-TABLE   is a read table in which all all graphic
  4734.      characters have ordinary  non-read-macro  constituent  syntax,  whitespace
  4735.      characters  have  whitespace  syntax,  and  other characters (e.g. control
  4736.      characters) are illegal.
  4737.  
  4738.          (WITH-INPUT-FROM-STRING (PORT " foo () ")
  4739.            (SET (PORT-READ-TABLE PORT) VANILLA-READ-TABLE)
  4740.            (LIST (READ PORT) (READ PORT)))
  4741.          =>  (FOO #[Symbol "()"])
  4742.  
  4743.  
  4744. (READ-TABLE-ENTRY table character) -> syntax                           Settable
  4745.  
  4746.      Access character's read syntax in table.  The entry for a given  character
  4747.      is  some  object  which represents the character's lexical properties, for
  4748.      example, whether it is a constituent, whitespace, or read-macro character.
  4749.      For  read-macro  characters,  the  entry  is  a  procedure for parsing the
  4750.      read-macro construct.
  4751.  
  4752.                                      -79-
  4753.  
  4754.  
  4755.      Values suitable to be stored in read tables may be obtained  by  accessing
  4756.      existing entries in the standard read table.  For example:
  4757.  
  4758.          (SET (READ-TABLE-ENTRY *MY-READ-TABLE* #\;)
  4759.               (READ-TABLE-ENTRY STANDARD-READ-TABLE #\:))
  4760.  
  4761.      makes  the  read syntax of semicolon in *MY-READ-TABLE* be the same as the
  4762.      standard read syntax of colon (which is a contituent character).
  4763.  
  4764.      To define a read macro, do
  4765.  
  4766.          (SET (READ-TABLE-ENTRY read-table character) procedure)
  4767.  
  4768.      where procedure is a procedure  taking  two  arguments:  a  port    and  a
  4769.      character.    The  port   is the port   which is currently being parsed by
  4770.      READ-OBJECT.  It may be passed as the port   argument  to  input  routines
  4771.      like  READC and READ-REFUSING-EOF if the read-macro needs to parse further
  4772.      characters from the input port.    The character is  the  character  which
  4773.      caused  the  read  macro to be invoked; that is, it is the character under
  4774.      which the procedure is stored in the read table.
  4775.  
  4776.      Example:
  4777.  
  4778.          (SET (READ-TABLE-ENTRY *MY-READ-TABLE* #\')
  4779.               (LAMBDA (PORT CH)
  4780.                 (IGNORE CH)
  4781.                 (LIST 'QUOTE (READ-REFUSING-EOF PORT))))
  4782.  
  4783.      Note that  the  standard  read  table  and  the  vanilla  read  table  are
  4784.      immutable, and so their entries may not be changed.
  4785.  
  4786.  
  4787. NOTHING-READ -> object                                                       
  4788.  
  4789.      Read  macros  should return this object, which is treated specially by the
  4790.      reader, if they want to return no object.   For  example,  the  semi-colon
  4791.      (comment) read-macro might be defined as follows:
  4792.  
  4793.          (SET (READ-TABLE-ENTRY *MY-READ-TABLE* #\;)
  4794.               (LAMBDA (PORT CH)
  4795.                  (ITERATE LOOP ()
  4796.                    (LET ((C (READC PORT)))
  4797.                      (COND ((EOF? C) C)
  4798.                            ((CHAR= C #\NEWLINE) *NOTHING-READ*)
  4799.                            (ELSE (LOOP)))))))
  4800.  
  4801.  
  4802. (DELIMITING-READ-MACRO? procedure) -> boolean                         Operation
  4803.  
  4804.      If an object which returns true to the DELIMITING-READ-MACRO? operation is
  4805.      stored in a read table under a given character, then the reader will treat
  4806.      the  character  as  a  delimiter (non-constituent) character.  By default,
  4807.      read-macro procedures return false to this predicate.    Thus  to  make  a
  4808.      read-macro  character  be  a delimiting character also (as are parentheses
  4809.      and semicolon in the standard read table), its  read  table  entry  should
  4810.      handle this operation by returning true.
  4811.  
  4812.                                      -80-
  4813.  
  4814.  
  4815.          (SET (READ-TABLE-ENTRY *MY-READ-TABLE* #\~)
  4816.               (OBJECT (LAMBDA (PORT CH)
  4817.                         ...)
  4818.                       ((DELIMITING-READ-MACRO? SELF) T)))
  4819.  
  4820.  
  4821. (MAKE-LIST-READER) -> list-reader                                              
  4822.  
  4823.      The  two  procedures  MAKE-LIST-READER  and  LIST-TERMINATOR  can  be used
  4824.      together  to  define  read  macros   which   behave   syntactically   like
  4825.      parentheses.
  4826.  
  4827.      Each  call  to  MAKE-LIST-READER returns an object which is a procedure of
  4828.      two arguments called a list reader.  Calling  LIST-TERMINATOR  on  a  list
  4829.      reader will return another object called its list terminator.
  4830.  
  4831.      List  readers  and  terminators  are suitable for entry in read tables.  A
  4832.      list reader acts as a read  macro  which  reads  a  sequence  of  objects,
  4833.      terminated  by  a  character  whose  read syntax is the corresponding list
  4834.      terminator.    For  example,  the  standard  syntax  for  left  and  right
  4835.      parentheses might be defined as follows:
  4836.  
  4837.          (LET ((LIST-READER (MAKE-LIST-READER)))
  4838.            (SET (READ-TABLE-ENTRY STANDARD-READ-TABLE #\LEFT-PAREN)
  4839.                 LIST-READER)
  4840.            (SET (READ-TABLE-ENTRY STANDARD-READ-TABLE #\RIGHT-PAREN)
  4841.                 (LIST-TERMINATOR LIST-READER)))
  4842.  
  4843.      Like  any  read-macro  procedure,  a  list  reader  is  a procedure of two
  4844.      arguments.  The first argument  must  be  a  port,    and  the  second  is
  4845.      ignored.    Thus instead of being stored in a read table, it may be called
  4846.      from another read-macro procedure.  For example, the following makes [...]
  4847.      an alternative read syntax for vectors:
  4848.  
  4849.          (LET ((LIST-READER (MAKE-LIST-READER)))
  4850.            (SET (READ-TABLE-ENTRY *MY-READ-TABLE* #\LEFT-BRACKET)
  4851.                 (OBJECT (LAMBDA (PORT CH)
  4852.                           (LIST->VECTOR (LIST-READER PORT CH)))
  4853.                         ((DELIMITING-READ-MACRO? SELF) T)))
  4854.            (SET (READ-TABLE-ENTRY *MY-READ-TABLE* #\RIGHT-BRACKET)
  4855.                 (LIST-TERMINATOR LIST-READER)))
  4856.  
  4857.      List  readers and terminators handle the DELIMITING-READ-MACRO?  operation
  4858.      by returning true.
  4859.  
  4860.  
  4861. (LIST-TERMINATOR list-reader) -> list-terminator                               
  4862.  
  4863.      Given a list reader, returns its list terminator.  See LIST-READER, above.
  4864.  
  4865.  
  4866. 14.3. Standard compiler
  4867.  
  4868. A  compiler  is a procedure which accepts an expression and a syntax table, and
  4869. returns a compiled code object.  A compiled code object may be  executed  in  a
  4870. given  environment.  Note that the term "compiler" is used in a technical sense
  4871.  
  4872.                                      -81-
  4873.  
  4874.  
  4875. and encompasses not only compilers such as  TC  (section  17.5)  which  produce
  4876. machine instructions, but also programs such as the standard compiler (which is
  4877. called by EVAL) which operate internally by producing intermediate code  or  by
  4878. interpreting  source  code  directly.    Often  programs  like these are called
  4879. interpreters instead of compilers.
  4880.  
  4881. A given T implementation may have several compilers.  STANDARD-COMPILER  should
  4882. be  one  of these compilers.  Tau 2.7 also provides a compiler called TC, which
  4883. is described in section 17.5.
  4884. (EVAL expression environment) -> object                                        
  4885.  
  4886.      Evaluates expression  in  environment.    Evaluation  is  performed  as  a
  4887.      two-stage  process:  first, the standard compiler compiles the expression,
  4888.      producing a compiled code object; then the compiled code object is invoked
  4889.      in the given environment.
  4890.  
  4891.          (EVAL expression environment)
  4892.            <=>
  4893.          (RUN-COMPILED-CODE (STANDARD-COMPILER expression
  4894.                                                (ENV-SYNTAX-TABLE environmen
  4895.                             environment)
  4896.  
  4897.  
  4898. (STANDARD-COMPILER expression syntax-table) -> compiled-code                   
  4899.  
  4900.      Compiles   expression.    An  implementation  of  T  may  provide  several
  4901.      compilers, of which STANDARD-COMPILER will be the one which is invoked  by
  4902.      EVAL.
  4903.  
  4904.  
  4905. (RUN-COMPILED-CODE compiled-code environment) -> object                        
  4906.  
  4907.      Invokes a compiled code object.
  4908.  
  4909.           Bug: In Tau 2.7, the environment passed to RUN-COMPILED-CODE must  be
  4910.           the   same   as   the   one   whose   syntax   table  was  passed  to
  4911.           STANDARD-COMPILER.
  4912.  
  4913.  
  4914. 14.4. Syntax tables
  4915.  
  4916. A syntax table maps symbols to syntax descriptors.  Every syntax descriptor  is
  4917. itself  either  a  macro  expander,  or  a unique token identifying a primitive
  4918. special form type.
  4919.  
  4920. Every locale has an associated syntax table.  A locale's syntax table  contains
  4921. definitions  of  special forms which are local to the locale.  Each such syntax
  4922. table inherits entries lexically from the syntax tables of enclosing locales.
  4923.  
  4924. Macros provide  a  mechanism  for  extending  the  syntax  of  T  by  means  of
  4925. source-to-source transformations.  As in many Lisp dialects, the macro facility
  4926. in T provides  a  powerful  tool  for  amplifying  the  expressiveness  of  the
  4927. language.    But like any powerful tool, macros may be abused.  They may easily
  4928. lead to programs that are very hard to understand.
  4929.  
  4930.                                      -82-
  4931.  
  4932.  
  4933. Macros are defined  by  entering  syntax  descriptor  objects  known  as  macro
  4934. expanders  into syntax tables; see SYNTAX-TABLE-ENTRY and DEFINE-SYNTAX, below.
  4935. Macros  may  also  be  defined  locally  to  a   file   or   expression   using
  4936. DEFINE-LOCAL-SYNTAX or LET-SYNTAX.
  4937.  
  4938. Procedure  integration  is  preferable to the use of macros in situations where
  4939. either would be applicable.  See DEFINE-INTEGRABLE, page 71.
  4940. (ENV-SYNTAX-TABLE environment) -> syntax-table                                 
  4941.  
  4942.      Returns the syntax table associated with environment.
  4943.  
  4944.  
  4945. (MAKE-SYNTAX-TABLE syntax-table identification) -> syntax-table                
  4946.  
  4947.      Creates a new syntax table inferior to the given syntax table.  Note  that
  4948.      syntax tables are created implicitly by MAKE-LOCALE (page 16).
  4949.  
  4950.  
  4951. STANDARD-SYNTAX-TABLE -> syntax-table                                        
  4952.  
  4953.      A syntax table with entries for all standard T reserved words.
  4954.  
  4955.          STANDARD-SYNTAX-TABLE  <=>  (ENV-SYNTAX-TABLE-ENTRY STANDARD-ENV)
  4956.  
  4957.  
  4958. (SYNTAX-TABLE-ENTRY syntax-table symbol) -> descriptor or false        Settable
  4959.  
  4960.      Accesses  the  syntax  descriptor  associated with symbol in syntax-table.
  4961.      Returns false if there is no such entry.
  4962.  
  4963.          (SYNTAX-TABLE-ENTRY STANDARD-SYNTAX-TABLE 'QUOTE)  =>  #{Syntax 
  4964.          (SYNTAX-TABLE-ENTRY STANDARD-SYNTAX-TABLE 'CAR)    =>  false
  4965.  
  4966.      Syntax   table   entries    may    be    created    or    altered    using
  4967.      (SET  (SYNTAX-TABLE-ENTRY  ...)  ...)    or  by  using  DEFINE-SYNTAX.  On
  4968.      assignment, descriptor may be false, in which case symbol loses any syntax
  4969.      table  entry  it  may  have had.  This allows it to be bound as a variable
  4970.      using DEFINE or LET, for example.
  4971.  
  4972.  
  4973. 14.5. Defining syntax
  4974.  
  4975. (DEFINE-SYNTAX symbol descriptor) -> undefined                                 
  4976. (DEFINE-SYNTAX (symbol . vars) . body) -> undefined
  4977.  
  4978.      Sets symbol's syntax table entry in the syntax table of the environment in
  4979.      which  the  DEFINE-SYNTAX  form is being evaluated.  The second form is an
  4980.      abbreviation for an equivalent expression  of  the  first  form  involving
  4981.      MACRO-EXPANDER:
  4982.  
  4983.          (DEFINE-SYNTAX (symbol . variables) . body)
  4984.            <=>
  4985.          (DEFINE-SYNTAX symbol
  4986.            (MACRO-EXPANDER (symbol . variables) . body))
  4987.  
  4988.      Macros and MACRO-EXPANDER are explained below.
  4989.  
  4990.                                      -83-
  4991.  
  4992.  
  4993.      As  with  (SET  (SYNTAX-TABLE-ENTRY ...) ...), descriptor may be false, in
  4994.      which case symbol loses any syntax table entry it  may  have  had.    This
  4995.      allows it to be bound as a variable using DEFINE or LET, for example.
  4996.  
  4997.      Note  that DEFINE-SYNTAX forms have no effect at compile time.  Using them
  4998.      indiscriminately may lead to code which behaves differently  depending  on
  4999.      what  compiler  is  being  used.    For example, a use of the special form
  5000.      defined by a DEFINE-SYNTAX form later on in the same  file  in  which  the
  5001.      DEFINE-SYNTAX form occurs may be seen as a valid special form reference by
  5002.      the standard compiler, but may be treated as a call by TC.
  5003.  
  5004.          (DEFINE-SYNTAX (REPEAT N . CODE)
  5005.            `(LET ((COUNT ,N)
  5006.                   (THUNK (LAMBDA () ,@CODE)))
  5007.               (DO ((COUNT COUNT (- COUNT 1)))
  5008.                   ((<= COUNT 0) NIL)
  5009.                 (THUNK))))
  5010.  
  5011.  
  5012. 14.6. Local syntax
  5013.  
  5014. Reserved  words  may  be  defined  at  compile  time   using   LET-SYNTAX   and
  5015. DEFINE-LOCAL-SYNTAX.   Syntax defined this way is called local syntax and is in
  5016. effect only at compile time, not at run time.
  5017.  
  5018. Local syntax is block structured, much as variables are.  The  outermost  local
  5019. syntax contour is the point at which a compiler is invoked, which usually means
  5020. a file boundary.  Inner contours are introduced by LET-SYNTAX forms.
  5021.  
  5022. Put another way, a local syntax table is created whenever a compiler is invoked
  5023. (LOAD,  COMFILE, EVAL) and whenever a LET-SYNTAX form is compiled.  Entries are
  5024. created in a local syntax table at compile time for syntax defined initially by
  5025. the  LET-SYNTAX form and later when the compiler encounters DEFINE-LOCAL-SYNTAX
  5026. forms.  The syntax table is used at compile time and is otherwise unavailable.
  5027. (LET-SYNTAX specs . body) -> value-of-body                                     
  5028.  
  5029.      Defines macros locally to body.  Yields the value  of  body,  an  implicit
  5030.      block.  Each spec should be either
  5031.  
  5032.          (symbol descriptor)
  5033.  
  5034.      or
  5035.  
  5036.          ((symbol . vars) . body)
  5037.  
  5038.      in analogy to DEFINE-SYNTAX.
  5039.  
  5040.      The  descriptor  and  body  forms  in specs will not necessarily run in an
  5041.      environment which is at all  related  to  the  environment  in  which  the
  5042.      program  in  which  the  LET-SYNTAX  form  occurred  will  be run, because
  5043.      compilation may occur independently of execution.  TC executes these forms
  5044.      in (TC-MACRO-DEFINITION-ENV) [T<3 only].    The standard compiler uses the    X10
  5045.      locale with which the syntax table passed to it is associated.    This  is
  5046.  
  5047.                                      -84-
  5048.  
  5049.  
  5050.      implementation-dependent,  and  subject to change.  For this reason, it is
  5051.      best to write local macros in such a way that no free variables or special
  5052.      forms  are used, other than those in the standard system environment, that
  5053.      is, those defined to be part of the T language.
  5054.  
  5055.      This disclaimer does not apply to the body of the LET-SYNTAX  form,  which
  5056.      is  evaluated  (except for syntax) exactly as if the LET-SYNTAX expression
  5057.      were a BLOCK expression.
  5058.  
  5059.          (LET-SYNTAX ((KWOTE (SYNTAX-TABLE-ENTRY STANDARD-SYNTAX-TABLE
  5060.                                                  'QUOTE)))
  5061.            (KWOTE (A B C)))
  5062.          =>  (A B C)
  5063.  
  5064.          (LET-SYNTAX ((SET NIL)) (LET ((SET LIST) (X 5)) (SET X 8)))  =>  (
  5065.  
  5066.          (LET-SYNTAX (((MAC X) `'(X = ,X))) (MAC Y))  =>  (X = Y)
  5067.  
  5068.           Bug: Tau 2.7 doesn't implement LET-SYNTAX.
  5069.  
  5070.  
  5071. (DEFINE-LOCAL-SYNTAX symbol descriptor) -> undefined               Special form
  5072. (DEFINE-LOCAL-SYNTAX (symbol . vars) . body) -> undefined
  5073.  
  5074.      Defines  syntax  locally  to  the body of the nearest enclosing LET-SYNTAX
  5075.      form, or, if the DEFINE-LOCAL-SYNTAX does not appear inside  a  LET-SYNTAX
  5076.      form,  then  to  the  file  or  outermost  expression  in which it occurs.
  5077.      Forward references are not defined to work; the  DEFINE-LOCAL-SYNTAX  form
  5078.      should appear prior to any use of symbol as a reserved word.
  5079.  
  5080.      The syntax of DEFINE-LOCAL-SYNTAX is analogous to that of DEFINE-SYNTAX.
  5081.  
  5082.      In  general,  DEFINE-LOCAL-SYNTAX should be used for syntax which is to be
  5083.      available only within the file in which it occurs.  If a syntax definition
  5084.      is  needed  for  several files, then they should be made available in some
  5085.      locale's syntax table by evaluating DEFINE-SYNTAX forms  in  that  locale,
  5086.      and  then  that  locale's  syntax  table  should be used when compiling or
  5087.      loading the file (see the SYNTAX-TABLE file header clause).
  5088.  
  5089.           Note: To ease incremental debugging, the standard compiler in Tau 2.7
  5090.           causes  syntax  defined  with  DEFINE-LOCAL-SYNTAX  to  be   retained
  5091.           indefinitely;  that is, they are entered into the syntax table of the
  5092.           locale which was passed to LOAD.  Programs should not  rely  on  this
  5093.           feature,  however, or code may behave differently when compiled using
  5094.           TC.
  5095.  
  5096.  
  5097. 14.7. Macro expanders
  5098.  
  5099. (MACRO-EXPANDER (identification . variables) . body) -> macro-expanderSpecial f
  5100.  
  5101.      Yields a macro expander.  A macro expander is a kind of syntax descriptor,
  5102.      and  may  therefore  be stored in a syntax table.  When a compiler using a
  5103.      symbol table S encounters a form whose car is a symbol, and the entry in S
  5104.      for that symbol is the object yielded by a MACRO-EXPANDER-expression, then
  5105.      the macro expander is invoked; that is, its variables  are  bound  to  the
  5106.      rest  of  form  (as  with  one level of DESTRUCTURE binding), the body (an
  5107.      implicit block) is evaluated, and the value is returned to  the  compiler.
  5108.      The compiler then compiles that form in place of the original one.
  5109.  
  5110.                                      -85-
  5111.  
  5112.  
  5113.      The  lexical context of body is that of the MACRO-EXPANDER form (augmented
  5114.      by the bindings of variables, of course), as with LAMBDA.
  5115.  
  5116.          (DEFINE M (MACRO-EXPANDER (FOO X Y Z) `(LIST 'FIRST ',X ,Y ,Z)))
  5117.          (INVOKE-MACRO-EXPANDER M '(BAR QUOTED (+ 1 2) (* 3 4)))
  5118.            =>  (LIST 'FIRST 'QUOTED  (+ 1 2) (* 3 4))
  5119.  
  5120.          (DEFINE L (MAKE-LOCALE STANDARD-ENV NIL))
  5121.          (SET (SYNTAX-TABLE-ENTRY (ENV-SYNTAX-TABLE L) 'BAR) M)
  5122.  
  5123.          (EVAL '(BAR QUOTED (+ 1 2) (* 3 4)) L)  =>  (FIRST QUOTED 3 12)
  5124.  
  5125.          (DEFINE-SYNTAX FOO
  5126.            (MACRO-EXPANDER (FOO THING FORM)
  5127.              `(LIST ,FORM ',THING)))
  5128.  
  5129.          (FOO (CONS 1 2) (CONS 3 5))  =>  ((3 . 5) (CONS 1 2))
  5130.  
  5131.      DESTRUCTURE (page 52) and quasiquote (page 53) are useful in writing macro
  5132.      expansion  procedures,  the first for taking apart the form which is to be
  5133.      expanded, the second for constructing the resultant code from templates.
  5134.  
  5135.      Note that for a macro definition to take effect at compile time,  it  must
  5136.      either be present in the syntax table being used by the compiler or defin-
  5137.      ed locally using LET-SYNTAX or DEFINE-LOCAL-SYNTAX.
  5138.  
  5139.  
  5140. (MACRO-EXPANDER? descriptor) -> boolean                                        
  5141.  
  5142.      Returns true if descriptor, which must be a syntax descriptor, is a  macro
  5143.      expander.
  5144.  
  5145.          (MACRO-EXPANDER? (MACRO-EXPANDER (FOO X) X))  =>  true
  5146.  
  5147.  
  5148. (INVOKE-MACRO-EXPANDER descriptor form) -> new-form                            
  5149.  
  5150.      Invokes  the  macro  expansion  procedure  for descriptor, which must be a
  5151.      macro expander.  (See MACRO-EXPANDER, above.)
  5152.  
  5153.          (INVOKE-MACRO-EXPANDER (MACRO-EXPANDER (FOO X) `(LAMBDA () ,X))
  5154.                                 '(BAZ (+ 1 2)))
  5155.            =>
  5156.          (LAMBDA () (+ 1 2))
  5157.  
  5158.  
  5159. (MACRO-EXPAND form syntax-table) -> new-form                                   
  5160.  
  5161.      Performs one macro expansion on the form, if it is a list whose car  is  a
  5162.      symbol,  there  is an entry in the given syntax-table for that symbol, and
  5163.      that entry is a macro expander.
  5164.  
  5165.                                      -86-
  5166.  
  5167.  
  5168. Chapter 15                                                                ports
  5169.  
  5170.  
  5171. A port   is any object which handles port   operations.   In  general,    ports
  5172. are  objects  which  contain  pointers  into  sequences of objects.  The   port
  5173. operations provide for obtaining objects from  such  a  sequence,  advancing  a
  5174. port's   pointer, performing side effects on the sequence itself, and so forth.
  5175.  
  5176. T programs communicate with the external world via ports.     ports  may access
  5177. file systems or terminals.  They may also be  used  to  implement  filters  and
  5178. buffers of various sorts.
  5179.  
  5180. ports    are  manipulated  using  generic  operations.   Most of the procedures
  5181. described below are generic operations, and their descriptions  either  specify
  5182. the  behavior  of  their  default methods or of the methods for system-supplied
  5183. ports.      Users  may  create  ports    to  their  own  specifications   using
  5184. OBJECT-expressions.     As  long  as  a  user   port   supports  READ-CHAR  and
  5185. UNREAD-CHAR (for input   ports) or WRITE-CHAR (for output   ports), most of the
  5186. other I/O operations will work with them.
  5187.  
  5188. 15.1. General
  5189.  
  5190. (PORT? object) -> boolean                            Type predicate operation
  5191.  
  5192.      Returns true if object is a port.
  5193.  
  5194.  
  5195. (INPUT-PORT? object) -> boolean                      Type predicate operation
  5196.  
  5197.      Returns true if object is an input port.
  5198.  
  5199.  
  5200. (OUTPUT-PORT? object) -> boolean                     Type predicate operation
  5201.  
  5202.      Returns true if object is an output port.
  5203.  
  5204.  
  5205. (INTERACTIVE-PORT? object) -> boolean                Type predicate operation
  5206.  
  5207.      Returns true if object is an interactive   port.  An interactive   port is
  5208.      any input   port which is likely to have a human being at the  other  end,
  5209.      for example, a terminal input   port.
  5210.  
  5211.  
  5212. (EOF? object) -> boolean                                         Type predicate
  5213.  
  5214.      Returns  true  if object is the end-of-file token.  ("End-of-port" would
  5215.      be a more appropriate term.)
  5216.  
  5217.  
  5218. EOF -> end-of-file                                                           
  5219.  
  5220.      This global variable holds the end-of-file token.
  5221.  
  5222.                                      -87-
  5223.  
  5224.  
  5225. (WITH-OPEN-STREAMS specs . body) -> object                         Special form
  5226.  
  5227.      WITH-OPEN-STREAMS has the same syntax as LET, and similar semantics.  Each
  5228.      spec  should  be of the form (variable port).    Each   port expression is
  5229.      evaluated, and should evaluate to a    port;  for  example,    port  would
  5230.      typically  be  an  expression  involving OPEN or MAYBE-OPEN.  The body, an
  5231.      implicit block, is evaluated in a lexical context in which  each  variable
  5232.      is bound to the value of the corresponding   port expression.  The   ports
  5233.      are closed, and the value of body is returned.
  5234.  
  5235.      WITH-OPEN-STREAMS is the preferred way to use   port  creation  operations
  5236.      such  as  OPEN.  It ensures that the   ports will be closed, even if there
  5237.      is a non-local exit (a (RESET) or any other kind of throw) out of body  or
  5238.      any of the   port expressions.  (See UNWIND-PROTECT, page 29.)
  5239.  
  5240.      For an example, see OPEN, page 98.
  5241.  
  5242.  
  5243. (CLOSE   port) -> undefined                                           Operation
  5244.  
  5245.      Closes    port;  indicates  that  no more input or output is intended, and
  5246.      that any resources associated with it may be freed.
  5247.  
  5248.  
  5249. (STRING->INPUT-PORT string) ->   port                                        
  5250.  
  5251.      Returns an input   port which yields successive characters  of  string  on
  5252.      successive READ-CHAR's.
  5253.  
  5254.  
  5255. (WITH-INPUT-FROM-STRING (variable string) . body) -> value-of-body Special form
  5256.  
  5257.      Opens  an  input    port  to  string,  binds  variable to that   port, and
  5258.      evaluates body, returning whatever body returns.  
  5259.  
  5260.          (WITH-INPUT-FROM-STRING (variable string) . body)
  5261.            <=>
  5262.          (WITH-OPEN-STREAMS ((variable (STRING->INPUT-PORT string)))
  5263.            . body)
  5264.  
  5265.  
  5266. (WITH-OUTPUT-TO-STRING var . body) -> string                       Special form
  5267.  
  5268.      Binds var to an output   port.  The body (an implicit block) is evaluated,
  5269.      and  any characters written to the   port are collected in a string, which
  5270.      is returned as the value of the WITH-OUTPUT-TO-STRING form.
  5271.  
  5272.          (WITH-OUTPUT-TO-STRING FOO (WRITE FOO '(A B)))  =>  "(A B)"
  5273.  
  5274.  
  5275.                                      -88-
  5276.  
  5277.  
  5278. 15.2. Port switches
  5279.  
  5280. (TERMINAL-INPUT) ->   port                                             Settable
  5281.  
  5282.      Accesses the default   port for input from the terminal.
  5283.  
  5284.      Note that an end-of-file condition on the terminal input port  will  cause
  5285.      the end-of-file token to be returned as the value of the next input  oper-
  5286.      ation on that port, but will not cause the port to become closed.  This is
  5287.      an exception to the normal rule that no input is available from ports fol-
  5288.      lowing an end-of-file condition on it.
  5289.  
  5290.  
  5291. (TERMINAL-OUTPUT) ->   port                                            Settable
  5292.  
  5293.      Accesses the default   port for output to the terminal.
  5294.  
  5295.  
  5296. (STANDARD-INPUT) ->   port                                             Settable
  5297.  
  5298.      Accesses the default standard input   port.  Initially, this is  the  same
  5299.      as the value of (TERMINAL-INPUT).
  5300.  
  5301.      The  intent  is  that  a  program could do all its input from the standard
  5302.      input   port.  By default, input would come from the terminal.   But  some
  5303.      procedure  could  set the standard input   port to be a file, for example,
  5304.      and then call the program, which would automatically read from  the  file.
  5305.      This same idea is used for all the following predefined   ports.
  5306.  
  5307.  
  5308. (STANDARD-OUTPUT) ->   port                                            Settable
  5309.  
  5310.      Accesses  the default standard output   port.  Initially, this is the same
  5311.      as the value of (TERMINAL-OUTPUT).
  5312.  
  5313.  
  5314. (ERROR-OUTPUT) ->   port                                               Settable
  5315.  
  5316.      Initially, yields the same value as (TERMINAL-OUTPUT).
  5317.  
  5318.  
  5319. (DEBUG-OUTPUT) ->   port                                               Settable
  5320.  
  5321.      Initially, yields the same value as (TERMINAL-OUTPUT).
  5322.  
  5323.  
  5324. 15.3. Input
  5325.  
  5326. (READ-CHAR   port) -> character or end-of-file                        Operation
  5327. (READC   port) -> character or end-of-file
  5328.  
  5329.      Reads a single character from   port, advances  the    port  pointer,  and
  5330.      returns  the  character  read.    If  no  character is available, then the
  5331.      end-of-file token is returned.
  5332.  
  5333.                                      -89-
  5334.  
  5335.  
  5336. (UNREAD-CHAR   port) -> undefined                                     Operation
  5337. (UNREADC   port) -> undefined
  5338.  
  5339.      Backs up   port's pointer into its corresponding sequence of characters by
  5340.      one  character.    This  causes  the  next READ-CHAR from   port to return
  5341.      character instead of actually reading another  character.    Character  is
  5342.      returned.    UNREAD-CHAR  is  convenient  for  implementing one-character-
  5343.      lookahead scanners.  Only the previous character READ-CHAR'ed from    port
  5344.      may be put back, and it may be put back only once.
  5345.  
  5346.  
  5347. (PEEK-CHAR   port) -> character or end-of-file                        Operation
  5348. (PEEKC   port) -> character or end-of-file
  5349.  
  5350.      Returns  the  next  character  available  on    port without advancing the
  5351.        port's pointer.  If no character is there then the end-of-file token  is
  5352.      returned.
  5353.  
  5354.          (PEEK-CHAR   port)  <=>
  5355.            (BLOCK0 (READ-CHAR   port) (UNREAD-CHAR   port))
  5356.  
  5357.  
  5358. (READ-LINE   port) -> string or end-of-file                           Operation
  5359.  
  5360.      Reads a line of input from   port and returns it as a string.  If no input
  5361.      is available then the end-of-file token is returned.
  5362.  
  5363.  
  5364. (READ   port) -> object or end-of-file                                Operation
  5365.  
  5366.      Reads an object from   port.  The default method simply calls READ-OBJECT,
  5367.      passing it the   port and the   port's current associated read table.  See
  5368.      READ-OBJECT, page 77, and   PORT-READ-TABLE, page 93.
  5369.  
  5370. (READ-REFUSING-EOF   port) -> object                                           
  5371.  
  5372.      This is like READ but should be used in cases where an end-of-file is  not
  5373.      appropriate  or  is  not  handled, such as within the definition of a read
  5374.      macro.
  5375.  
  5376.  
  5377. (READ-OBJECTS-FROM-STRING string) -> list                                      
  5378.  
  5379.      Returns a list of all the objects that could be read from the string.
  5380.  
  5381.          (READ-OBJECTS-FROM-STRING "A B C")           =>  (A B C)
  5382.          (READ-OBJECTS-FROM-STRING " 015  ( Foo ) ")  =>  (15 (FOO))
  5383.          (READ-OBJECTS-FROM-STRING "")                =>  ()
  5384.  
  5385.  
  5386. (CLEAR-INPUT   port) -> undefined                                     Operation
  5387.  
  5388.      Discards any buffered input for    port.    The  precise  action  of  this
  5389.      operation is implementation-dependent.
  5390.  
  5391.                                      -90-
  5392.  
  5393.  
  5394. 15.4. Output
  5395.  
  5396. (PRINT object   port) -> undefined                                    Operation
  5397.  
  5398.      Prints  object  on   port according to the current read-table.  This is an
  5399.      operation, so objects may decide how they would like to print.
  5400.  
  5401.  
  5402. (WRITE   port object) -> undefined                                    Operation
  5403.  
  5404.      Prints the object on   port.  This is like PRINT with the  argument  order
  5405.      reversed.  This is an operation, so particular   ports may decide how they
  5406.      want to write objects to themselves.
  5407.  
  5408.  
  5409. (WRITE-CHAR   port character) -> undefined                            Operation
  5410. (WRITEC   port character) -> undefined
  5411.  
  5412.      Writes a single character to   port.
  5413.  
  5414.  
  5415. (WRITE-STRING   port string) -> undefined                             Operation
  5416. (WRITES   port string) -> undefined
  5417.  
  5418.      Writes string to   port.
  5419.  
  5420.  
  5421. (WRITE-LINE   port string) -> undefined                               Operation
  5422.  
  5423.      Writes  string  to    port  (like  WRITE-STRING),  then  does  a   NEWLINE
  5424.      operation.
  5425.  
  5426.  
  5427. (WRITE-SPACES   port count) -> undefined                                       
  5428.  
  5429.      Writes count space characters to   port.
  5430.  
  5431.  
  5432. (DISPLAY object   port) -> undefined                                  Operation
  5433.  
  5434.      Prints  object  on    port,  but omits any slashes, delimiters, etc., when
  5435.      printing strings, symbols, and characters.
  5436.  
  5437.  
  5438. (PRETTY-PRINT object   port) -> undefined                             Operation
  5439.  
  5440.      Pretty-prints object on   port.
  5441.  
  5442.  
  5443. (NEWLINE   port) -> undefined                                         Operation
  5444.  
  5445.      Begins a new line on the given output   port.
  5446.  
  5447.  
  5448. (FRESH-LINE   port) -> undefined                                      Operation
  5449.  
  5450.      If not at the beginning of a line, begins a new line on the  given  output
  5451.        port.
  5452.  
  5453.                                      -91-
  5454.  
  5455.  
  5456. (SPACE   port) -> undefined                                           Operation
  5457.  
  5458.      Write  whitespace  to    port.   Ordinarily this will simply write a space
  5459.      character, but if the current output line has  overflowed  a  "reasonable"
  5460.      right margin, this will do a NEWLINE.
  5461.  
  5462.  
  5463. (FORCE-OUTPUT   port) -> undefined                                    Operation
  5464.  
  5465.      Makes  sure  any  buffered output to   port is forced out.  This is useful
  5466.      especially with terminal output   ports.  The  precise  behavior  of  this
  5467.      operation is implementation-dependent.
  5468.  
  5469.  
  5470. 15.5. Formatted output
  5471.  
  5472. (FORMAT destination control-string . rest) -> string or undefined              
  5473.  
  5474.      Performs  formatted  output.   Characters in the control-string other than
  5475.      tilde (~) are simply written to destination.  When a tilde is encountered,
  5476.      special action is taken according to the character following the tilde.
  5477.  
  5478.      Destination should be one of the following:
  5479.  
  5480.         - A   port.  In this case, output is simply written to the   port.
  5481.           The value returned by the call to FORMAT is undefined.
  5482.  
  5483.         - The standard true value.  (This  is  the  value  of  the  system
  5484.           variable  T.)    This  is  equivalent  to  a    port argument of
  5485.           (STANDARD-OUTPUT).  The value returned by the call to FORMAT  is
  5486.           undefined.
  5487.  
  5488.         - Null.  In this case the output is collected in a string, as with
  5489.           WITH-OUTPUT-TO-STRING.  This string is returned as the value  of
  5490.           the call to FORMAT.
  5491.  
  5492.      The  FORMAT  control sequences are as follows.  (Case is irrelevant, so ~A
  5493.      and ~a behave identically.)
  5494.  
  5495.             ~A  DISPLAY the next format argument.
  5496.             ~B  Print the next argument in binary.
  5497.             ~D  Print the next argument in decimal (radix ten).
  5498.             ~O  Print the next argument in octal (radix eight).
  5499.             ~P  Write the character "s" if the next argument,
  5500.                     which must be a number, is not equal to 1 (for plurals)
  5501.             ~R  ~nR prints the next argument in radix n.
  5502.             ~S  PRINT the next format argument.
  5503.             ~T  ~nT tabs to column n (HPOS).
  5504.             ~X  Print the next argument in hexadecimal (radix sixteen).
  5505.             ~%  Go to a new output line (NEWLINE).
  5506.             ~&  Go to a fresh output line (FRESH-LINE).
  5507.             ~_  Print a space, or go to a fresh output line (SPACE).
  5508.             ~~  Write a tilde.
  5509.  
  5510.                                      -92-
  5511.  
  5512.  
  5513.      A tilde followed by any whitespace character is ignored,  along  with  all
  5514.      following whitespace.
  5515.  
  5516.          (FORMAT NIL "The ~s eats grass." 'ELAND)  =>  "The ELAND eats gras
  5517.          (FORMAT NIL "The ~A eats grass." "kudu")  =>  "The kudu eats grass
  5518.          (FORMAT NIL "~S had ~X goat~P." '(SANDY SMITH) 31 31)
  5519.            =>  "(SANDY SMITH) had 1F goats."
  5520.  
  5521.  
  5522. 15.6. Miscellaneous
  5523.  
  5524. (PORT-READ-TABLE   port) -> read-table                       Settable operation
  5525.  
  5526.      Accesses the read table associated with   port.  See section 14.2.
  5527.  
  5528.  
  5529. (LINE-LENGTH   port) -> integer                              Settable operation
  5530.  
  5531.      Returns  the maximum width that lines read from   port are likely to take,
  5532.      or that lines written to   port ought to take.
  5533.  
  5534.           Bug:  In  Tau  2.7, the LINE-LENGTH of system-supplied   ports is not
  5535.           settable.
  5536.  
  5537.  
  5538. (HPOS   port) -> integer                                     Settable operation
  5539.  
  5540.      Accesses the current horizontal position (column number) of   port.    The
  5541.      leftmost position on a line is column 0.  When assigned, as many spaces as
  5542.      necessary are written to bring the horizontal  position  to  the  assigned
  5543.      value.
  5544.  
  5545.  
  5546. (VPOS   port) -> integer                                     Settable operation
  5547.  
  5548.      Accesses  the  current  vertical  position  (line  number) of   port.  The
  5549.      uppermost vertical position is line 0.
  5550.  
  5551.  
  5552. (WITH-OUTPUT-WIDTH-STREAM variable . body) -> integer              Special form
  5553.  
  5554.      Binds variable to an output   port, and evaluates body  in  the  augmented
  5555.      lexical  environment.    The  characters sent to the output   port are not
  5556.      accumulated, but merely counted, and the total is returned as the value of
  5557.      WITH-OUTPUT-WIDTH-STREAM.
  5558.  
  5559.  
  5560. (PRINTWIDTH object) -> integer                                                 
  5561.  
  5562.      Returns  the number of WRITEC's which would be performed were object to be
  5563.      printed using PRINT.  
  5564.  
  5565.          (PRINTWIDTH object)
  5566.            <=>
  5567.          (WITH-OUTPUT-WIDTH-STREAM PORT (PRINT object PORT))
  5568.  
  5569.                                      -93-
  5570.  
  5571.     
  5572. (DISPLAYWIDTH object) -> integer                                               
  5573.  
  5574.      Returns the number of WRITEC's which would be performed were object to  be
  5575.      printed using DISPLAY.  
  5576.  
  5577.          (DISPLAYWIDTH object)
  5578.            <=>
  5579.          (WITH-OUTPUT-WIDTH-STREAM PORT (DISPLAY object PORT)
  5580.  
  5581.  
  5582. (MAKE-BROADCAST-PORT . output-ports) ->   port                             
  5583.  
  5584.      Returns  a    port  which will "broadcast" all output operations to all of
  5585.      the output-ports.    For example, if the   port s is the value of a call
  5586.  
  5587.          (MAKE-BROADCAST-PORT q r)
  5588.  
  5589.      then any WRITEC (WRITES, SPACE, etc.) operation to s will result in WRITEC
  5590.      operations on both q and r.
  5591.  
  5592.  
  5593. 15.7. Example
  5594.  
  5595. Here  is  an  example of a user-defined   port.  MAKE-PREFIXED-PORT   returns a
  5596. port which prefixes each line written to a given   port with a given string.
  5597.  
  5598.     (DEFINE (MAKE-PREFIXED-PORT PORT PREFIX)
  5599.       (JOIN (OBJECT NIL
  5600.                     ((NEWLINE SELF) (NEWLINE PORT) (WRITES PORT PREFIX)
  5601.                     ((PRINT SELF OPORT)
  5602.                      (FORMAT OPORT
  5603.                              "#{Prefixed-port~_~S~_~S}"
  5604.                              PORT
  5605.                              PREFIX)))
  5606.             PORT))
  5607.  
  5608.                                      -94-
  5609.  
  5610.  
  5611. Chapter 16                                                                Files
  5612.  
  5613.  
  5614. An executing T system interacts with the world outside  by  communicating  with
  5615. various external entities, including:
  5616.  
  5617.    - people, via keyboards and displays;
  5618.  
  5619.    - file   systems,   via   operating   system  calls,  possibly  over  a
  5620.      communications network;
  5621.  
  5622.    - and processes, running on the same machine or on different  machines.
  5623.  
  5624. The language provides simple standardized interfaces to the first two of these.
  5625. Particular implementations may provide more complete interfaces.
  5626.  
  5627. Standard access to a terminal is provided by  the    ports  TERMINAL-INPUT  and
  5628. TERMINAL-OUTPUT  (page  90).    Access  to  file  systems  is  provided  by the
  5629. facilities described in this chapter.
  5630.  
  5631.      Disclaimer: The file naming facilities described in this chapter are quite
  5632.      preliminary and are subject to change and elaboration.  This documentation
  5633.      corresponds to what is available in Tau 2.7.
  5634.  
  5635.  
  5636. 16.1. File systems
  5637.  
  5638. A  file  system  is a collection of named permanent objects called files, and a
  5639. mechanism for manipulating this collection.  A file system object is a T object
  5640. which  names  or  represents  an  actual file system.  Where the distinction is
  5641. unimportant, a file system object is referred to simply as a file system.
  5642.  
  5643. A given T implementation may provide access to multiple file  systems;  such  a
  5644. facility  is  not  described  in  this manual.  However, one may assume that at
  5645. least one file system, known as the local file system, is accessible.
  5646. (LOCAL-FS) -> file-system                                                      
  5647.  
  5648.      Returns the local file system object.
  5649.  
  5650.  
  5651. The following type predicates are defined to query the type of a file system.
  5652. (AEGIS-FS? file-system) -> boolean                               Type predicate
  5653.  
  5654.      Returns true if file-system represents an Aegis file system.
  5655.  
  5656.  
  5657. (UNIX-FS? file-system) -> boolean                                Type predicate
  5658.  
  5659.      Returns true if file-system represents a Unix file system.
  5660.  
  5661.  
  5662. (VMS-FS? file-system) -> boolean                                 Type predicate
  5663.  
  5664.      Returns true if file-system represents a VMS file system.
  5665.  
  5666.  
  5667.                                      -95-
  5668.  
  5669.  
  5670. 16.2. Filenames
  5671.  
  5672. A filename is an object which names a file.   Filenames  are  immutable  record
  5673. structures with the following components:
  5674.  
  5675.    - File  system:  the  file  system  object  via which the named file is
  5676.      accessible.
  5677.  
  5678.    - Directory: a collection of files within the file system to which  the
  5679.      named file belongs.
  5680.  
  5681.    - Name:  the  name  of the file within the directory, or of a family of
  5682.      files,  as  further  specified  by  the  file  type  and   generation
  5683.      components of the filename.
  5684.  
  5685.    - Type: the type of the file (also known as "extension").
  5686.  
  5687.    - Generation:  a  positive  integer  specifying a particular version or
  5688.      incarnation of the file.  Larger generation  numbers  indicate  newer
  5689.      versions.
  5690.  
  5691. In  general,  the  directory,  name,  and type components of a file are usually
  5692. symbols, the file system component is a file system object, and the  generation
  5693. component is an integer.  The file system component may be a symbol which names
  5694. a file system in an implementation-dependent manner.
  5695.  
  5696. Filenames may be incompletely specified; missing components are represented  by
  5697. having  null  (false)  as  their  value.    An  omitted  file system is usually
  5698. interpreted to be the same as the  local  file  system,  an  omitted  directory
  5699. component  means  the current working directory.  The name component may not be
  5700. omitted.
  5701.  
  5702. The external representation of a filename has the form
  5703.  
  5704.     #[Filename file-system dir name type gen]
  5705.  
  5706. where gen and type may be omitted, if null.
  5707. (MAKE-FILENAME file-system dir name type gen) -> filename                      
  5708. (MAKE-FILENAME file-system dir name type) -> filename
  5709. (MAKE-FILENAME file-system dir name) -> filename
  5710.  
  5711.      Returns a filename.  The arguments become the components of  the  filename
  5712.      object.    Type and gen may be omitted, in which case they default to null
  5713.      (absent).
  5714.  
  5715.  
  5716. (->FILENAME filespec) -> filename                                              
  5717.  
  5718.      Coerces filespec to a filename.
  5719.  
  5720.         - If filespec is a filename, then it is returned.
  5721.  
  5722.         - If filespec is a list l, then MAKE-FILENAME is  called,  passing
  5723.           null  as  the file system argument, and the elements of the list
  5724.           as the rest of the arguments.
  5725.  
  5726.         - If filespec is a symbol x, then it is treated the  same  as  the
  5727.           list (() x).
  5728.  
  5729.         - If  filespec  is a string, then it is converted to a filename in
  5730.           an  implementation-dependent  way,  such  that  FILENAME->STRING
  5731.           applied  to  the filename will return a string which is equal to
  5732.           filespec.
  5733.                                      -96-
  5734.  
  5735.  
  5736.      For example:
  5737.  
  5738.          (->FILENAME '#[Filename () MATH FACT T])  =>  #[Filename () MATH F
  5739.          (->FILENAME '(MATH FACT T))               =>  #[Filename () MATH F
  5740.          (->FILENAME '(MATH FACT))                 =>  #[Filename () MATH F
  5741.          (->FILENAME 'FACT)                        =>  #[Filename () () FAC
  5742.          (->FILENAME "fact.t")                     =>  #[Filename () () FAC
  5743.  
  5744.      The last example is plausible, but it will not necessarily hold in  all  T
  5745.      implementations, since the coercion of strings to filenames is not defined
  5746.      here.  (In  Tau  2.7,  strings  are  not  parsed  into  separate  filename
  5747.      components.)
  5748.  
  5749.  
  5750. (FILENAME? object) -> boolean                                    Type predicate
  5751.  
  5752.      Returns true if object is a filename.
  5753.  
  5754.  
  5755. (FILENAME-FS filename) -> file-system or false                                 
  5756.  
  5757.      Returns  the  file system component of filename, or false (null) if it has
  5758.      none.
  5759.  
  5760.  
  5761. (FILENAME-DIR filename) -> symbol or false                                     
  5762.  
  5763.      Returns the directory component of filename.
  5764.  
  5765.  
  5766. (FILENAME-NAME filename) -> symbol                                             
  5767.  
  5768.      Returns the name component of filename.
  5769.  
  5770.          (FILENAME-NAME '#[Filename () MATH FACT T])  =>  FACT
  5771.  
  5772.  
  5773. (FILENAME-TYPE filename) -> symbol or false                                    
  5774.  
  5775.      Returns the type component of filename.
  5776.  
  5777.  
  5778. (FILENAME-GENERATION filename) -> integer or false                             
  5779.  
  5780.      Returns the generation component of filename.
  5781.  
  5782.  
  5783. (FILENAME->STRING filename) -> string                                          
  5784.  
  5785.      Returns a string representing filename in the native syntax of  filename's
  5786.      file system (or of the local file system if filename is null).
  5787.  
  5788.      In Tau 2.7, if the directory component of filename is a symbol, then it is
  5789.      interpreted as a "logical name" in a manner idiosyncratic to the  type  of
  5790.      the file system:
  5791.  
  5792.         - Aegis:  a  T  logical name is interpreted as being a link in the
  5793.           naming directory.
  5794.  
  5795.         - Unix: a T logical name is an environment variable.
  5796.  
  5797.         - VMS: a T logical name is a VMS logical name.
  5798.  
  5799.                                      -97-
  5800.  
  5801.  
  5802.      For example:
  5803.  
  5804.          (FILENAME->STRING '#[Filename AN-AEGIS-FS MATH FACT T])
  5805.            =>  "~math/fact.t"
  5806.          (FILENAME->STRING '#[Filename A-UNIX-FS MATH FACT T])
  5807.            =>  "/usr/math/fact.t"
  5808.          (FILENAME->STRING '#[Filename A-VMS-FS MATH FACT T])
  5809.            =>  "MATH:FACT.T"
  5810.  
  5811.      (In the Unix example, we assume that environment variable MATH was defined
  5812.      to be /usr/math, e.g. by a "setenv MATH /usr/math" shell command.)
  5813.  
  5814.  
  5815. 16.3. Files
  5816.  
  5817. A  file  is  an  external  permanent object stored in a file system.  Files are
  5818. accessed in T via   ports.  Ordinarily,  files  are  sequences  of  characters,
  5819. similar  to  strings.    An  input    port  open  on  an existing file delivers
  5820. successive characters (or lines, or parsed objects) out of the file.  An output
  5821.   port  open on a new file deposits successive characters (or lines, or printed
  5822. representations of objects) into the file.
  5823.  
  5824. OPEN and MAYBE-OPEN obtain   ports which access files.  Any   port  created  by
  5825. OPEN  or  MAYBE-OPEN should be closed (using the CLOSE operation, page 89) when
  5826. no further access to the file is required.  This  is  guaranteed  if  OPEN  and
  5827. MAYBE-OPEN  are  always  used  in conjunction with WITH-OPEN-STREAMS (page 90),
  5828. which ensures that any   port opened actually gets closed, even if there  is  a
  5829. throw out of the body of the WITH-OPEN-STREAMS form.
  5830. (OPEN filespec mode-list) ->   port                                            
  5831.  
  5832.      Opens  an  external  file for reading or for writing, and returns a   port
  5833.      which accesses it.  Filespec should be a  filename  or  any  other  object
  5834.      which  can  be coerced to one (see ->FILENAME, page 96).  Mode-list should
  5835.      be a list of keywords (symbols) specifying what kind of access to the file
  5836.      is  desired.    The  only  keywords  currently recognized are IN, OUT, and
  5837.      APPEND, indicating reading, writing, and appending, respectively.   It  is
  5838.      an error condition if the file cannot be opened for some reason.
  5839.  
  5840.          (WITH-OPEN-STREAMS ((PORT (OPEN "file.txt" '(IN))))
  5841.            (READ-LINE PORT))
  5842.  
  5843.  
  5844. (MAYBE-OPEN filespec modes) ->   port or false                                 
  5845.  
  5846.      Like OPEN, but returns false if for any reason it cannot open the file.
  5847.  
  5848.  
  5849. (PORT-NAME   port) -> filename                                        Operation
  5850.  
  5851.      Returns  the filename of the file on which   port is open.  This operation
  5852.      is not handled by any system-created   ports other than those  created  by
  5853.      OPEN and MAYBE-OPEN.
  5854.  
  5855.  
  5856. (FILE-EXISTS? filespec) -> boolean                                             
  5857.  
  5858.      Returns true if the specified file exists.
  5859.  
  5860.  
  5861.                                      -98-
  5862.  
  5863. (FILE-MOVE source-filespec dest-filespec) -> undefined                         
  5864.  
  5865.      Moves  the  file  named  by  source-filespec  to  a  new location given by
  5866.      dest-filespec.  In some cases, this operation  can  be  performed  without
  5867.      actually  copying  the  file, for example, if the two locations are on the
  5868.      same "volume" of the same file system.  In this case, FILE-MOVE is  simply
  5869.      a rename operation.  In other cases, it may be more expensive.
  5870.  
  5871.           Bug: Not all versions of Tau 2.7 implement FILE-MOVE.
  5872.  
  5873.  
  5874.  
  5875. (FILE-DELETE filespec) -> undefined                                            
  5876.  
  5877.      Deletes the specified file.
  5878.  
  5879.           Bug: Not all versions of Tau 2.7 implement FILE-DELETE.
  5880.  
  5881.                                      -99-
  5882.  
  5883.  
  5884. Chapter 17                                                    Program structure
  5885.  
  5886.  
  5887. This  chapter  provides  information  about  organizing, loading, and compiling
  5888. programs.
  5889.  
  5890. 17.1. Environment structure
  5891.  
  5892. Lexical environments in T are hierarchically arranged.  Variable  bindings  are
  5893. inherited  from outer (superior) contours to inner (inferior) ones.  At the top
  5894. of the hierarchy is a root environment, which has no bindings in it.   Inferior
  5895. to  that  is  a standard environment which has bindings for all standard system
  5896. variables, for example, CAR and +.    (See  section  2.3.)    Inferior  to  the
  5897. standard  environment  are environments into which programs have been or are to
  5898. be loaded.  In the standard environment, the variable STANDARD-ENV    is  bound
  5899. to the standard environment itself.
  5900.  
  5901. When  a  T  system  starts  up, it sets up an initial environment configuration
  5902. which has one environment inferior to  the  standard  environment,  called  the
  5903.    user  environment.    The  variable     USER-ENV    is bound in the standard
  5904. environment to the     user  environment.    The     user  environment  has  no
  5905. variable  bindings  in  it  at first; however, the initial read-eval-print loop
  5906. (section 18.2) is started in this environment, so that if no other provision is
  5907. made,  user  global  variable  (i.e.  definitions)  will be made in the    user
  5908. environment.
  5909.  
  5910. In Tau 2.7, there is another environment called the implementation  environment
  5911. This is the value of T-IMPLEMENTATION-ENV in the standard environment. The imp-
  5912. lementation environment is not inferior to the standard  environment,  but  in-
  5913. stead is inferior to the root.
  5914.  
  5915.                                 ------ root environment (empty) ----------
  5916.                                /                            |             \
  5917.                 -------  STANDARD-ENV  ------      T-IMPLEMENTATION-ENV    
  5918.                /      |        |      ...    \
  5919.         USER-ENV    TC-ENV    EWE-ENV    other environments
  5920.                                         /      ...         \
  5921. [This system has changed in T>3]       ...                 ...                     X18
  5922.  
  5923. Empty  environments  may  be  created  using  MAKE-EMPTY-LOCALE  (page 16). For
  5924. example:
  5925.  
  5926.     (DEFINE *ALMOST-USELESS-ENV* (MAKE-EMPTY-LOCALE '*ALMOST-USELESS-ENV*))
  5927.     (*DEFINE *ALMOST-USELESS-ENV* '+ +)
  5928.     (*DEFINE *ALMOST-USELESS-ENV* '- -)
  5929.     (EVAL '(+ 5 (- 21 13)) *ALMOST-USELESS-ENV*)  =>  13
  5930.  
  5931. STANDARD-ENV -> locale                                                       
  5932.  
  5933.      The value of STANDARD-ENV   is an environment  (a  locale)  in  which  all
  5934.      system  variables  have  appropriate  values, as described in this manual.
  5935.      That is, it is a standard environment in the sense of section 2.3.
  5936.  
  5937.  
  5938.                                      -100-
  5939.  
  5940.  
  5941. USER-ENV -> locale                                                        
  5942.  
  5943.      The value of    USER-ENV  is  an  environment  (a  locale)  inferior  to
  5944.      STANDARD-ENV.  It is provided by a T implementation as an environment in
  5945.      which  a  user  may  evaluate  expressions  and  write  programs.    Other
  5946.      evaluation   environments  may  be  created  inferior  to  STANDARD-ENV,
  5947.      however, with MAKE-LOCALE (page 16).
  5948.  
  5949.  
  5950. 17.2. Source files
  5951.  
  5952. T programs are usually represented by collections of one  or  more  text  files
  5953. resident  in a file system.  Text files containing T programs are called source
  5954. files.
  5955.  
  5956. A source file consists  of  a  sequence  of  (external  representations  of)  T
  5957. expressions.   Source files may be loaded into a T environment.  When a file is
  5958. loaded, the expressions in the file are evaluated.  Typically, this means  that
  5959. useful  side-effects,  such as procedure definitions, occur which then make the
  5960. program available in that T environment.
  5961.  
  5962. A compilation (semantic analysis) step must occur either as  a  file  is  being
  5963. loaded,  or  prior  to  loading  the  file.  In the former case, compilation is
  5964. typically performed by a compiler such as the  "standard  compiler" (page 80ff)
  5965. which  itself runs relatively quickly and produces intermediate code which must
  5966. then be interpreted.  In the latter case, an auxiliary file known as an  object
  5967. file is involved; the compilation step need only be performed once, even if the
  5968. file is to be loaded many times.  (The term object file is completely unrelated
  5969. to the term object.)
  5970.  
  5971. A file compiler (such as TC; see section 17.5) takes a source file as input and
  5972. produces an object file as output.  The object file may then be loaded in  lieu
  5973. of the source file, with the same effect.
  5974.  
  5975.      Note: In the current implementation, the standard compiler cannot be  used
  5976.      as a file compiler, and TC cannot be used as an "on-the-fly" compiler.  In
  5977.      principle, the  two  dimensions  of  compiler  and  compilation  mode  are
  5978.      orthogonal:    it  should  be  possible  to  use either compiler in either
  5979.      manner.  In practice, this is not the case, but it turns out not to be too
  5980.      much of a problem.
  5981.  
  5982. 17.3. File syntax
  5983.  
  5984. The  first form in a source file must be a list whose car is the symbol HERALD.
  5985. This form is not an expression, but rather is part of the syntax of  the  file.
  5986. It  provides  information relevant to programs which operate on the source file
  5987. (such as readers, compilers, and loaders).  The syntax of a HERALD-form  is  as
  5988. follows:
  5989.  
  5990.     (HERALD identification . items)
  5991.  
  5992. Identification  should  be  either () or a symbol identifying the file (usually
  5993. the same as the root of the name of the file).  It is for documentary  purposes
  5994. only.
  5995.  
  5996. Items  is  a  sequence  of  lists.  Each item should be a list beginning with a
  5997. valid keyword symbol, as described below.
  5998.  
  5999.                                      -101-
  6000.  
  6001.  
  6002. Example:
  6003.  
  6004.     (HERALD FACT
  6005.             (READ-TABLE *MATH-READ-TABLE*)
  6006.             (ENV T (MATH MATHMACROS)))
  6007.  
  6008. (READ-TABLE expression)                                             Herald item
  6009.  
  6010.      Expression should evaluate to a read table, which is used in  reading  the
  6011.      expressions  which  follow  the  HERALD-form  from  the  source file.  The
  6012.      environment in which  expression  is  evaluated  depends  on  the  program
  6013.      processing the file (but might be, e.g., the    user environment).
  6014.  
  6015.      If  this item is absent, then expressions are read using the standard read
  6016.      table.
  6017.  
  6018.  
  6019. (SYNTAX-TABLE expression)                                           Herald item
  6020.  
  6021.      Expression should evaluate to a syntax table, which is used  in  compiling
  6022.      (evaluating) the expressions in the source file.  The environment in which
  6023.      expression is evaluated depends on the program processing  the  file  (but
  6024.      might be, e.g., the    user environment).
  6025.  
  6026.      If  this  item  is  absent,  then expressions are compiled according to an
  6027.      appropriate syntax table: the syntax table associated with the locale into
  6028.      which  the  file  is  being  loaded,  if  the file is being loaded, or the
  6029.      current value of (TC-SYNTAX-TABLE) (see  below),  if  the  file  is  being
  6030.      compiled using TC.
  6031.  
  6032.           Bug: In Tau 2.7, this works in TC, but is  ignored  in  the  standard
  6033.           compiler  (that  is, when loading a source file directly).  LOAD will
  6034.           always use the syntax table of the environment into which the file is
  6035.           being loaded.
  6036.  
  6037.  
  6038. (ENV support-env-name . filespecs)                                  Herald item
  6039.  
  6040.      Specifies  a  support  (early binding) environment for compiling the file.
  6041.      The support environment consists  of  the  support  environment  named  by
  6042.      support-env-name,  augmented  by  information  obtained from support files
  6043.      named by filespecs.
  6044.  
  6045.      If this item is absent, then the standard support environment, whose  name
  6046.      is  T, is used.  The ability to create and name other support environments
  6047.      is not yet documented.
  6048.  
  6049.  
  6050. 17.4. Loading files
  6051.  
  6052. (LOAD filespec environment) -> undefined                                       
  6053.  
  6054.      Loads the file named by filespec.  If the file is a source file, then each
  6055.      expression in the file is compiled (with the standard compiler) and run in
  6056.      environment.  If the file is an object file, as produced by TC,  then  the
  6057.      compiled object code is simply run in environment.
  6058.  
  6059.      If  no  explicit  file  type is given in the filespec, then LOAD will load
  6060.      either an object file (file type BIN), if one exists,  or  a  source  file
  6061.      (file type T) otherwise.
  6062.  
  6063.                                      -102-
  6064.  
  6065.  
  6066. 17.5. File compilation
  6067.  
  6068. In  addition  to the standard compiler invoked when EVAL or LOAD is called, Tau
  6069. provides a so-called optimizing compiler.  This compiler, known as TC  (for  "T
  6070. compiler"),  trades  compilation  speed  for execution speed: STANDARD-COMPILER
  6071. tries to compile quickly, while TC tries to generate executable code which will
  6072. run fast.
  6073.  
  6074. To help produce more efficient code, TC makes assumptions about the values that
  6075. some variables will have at run-time.    These  assumptions  are  called  early
  6076. bindings.   For example, it will ordinarily assume that the variable PAIR? will
  6077. have the standard PAIR? predicate as its top-level value.  This means  that  if
  6078. an  object  file  produced  under  this  assumption  is  loaded  into a lexical
  6079. environment where this is not the case, then calls to PAIR?  will  not  execute
  6080. the same as they would if the source file had been loaded.
  6081.  
  6082. Early bindings are obtained from support environments.  The support environment
  6083. to be used in compiling a file may be specified by an ENV clause in the  file's
  6084. header. A support environment may contain user-defined integrable procedure and
  6085. constant definitions.
  6086.  
  6087. Besides early binding, another source of improved efficiency is a difference in
  6088. the  handling  of  undefined  effects (that is, run-time program errors).  When
  6089. code compiled using  the  standard  compiler  incurs  an  error,  an  error  is
  6090. signalled,  and  the error system is entered, giving the user an opportunity to
  6091. debug the problem at the point where it occurs.  Code  compiled  using  TC  has
  6092. less  error-checking,  so  the  effect  of an error may go unnoticed until long
  6093. after the error occurred, or a secondary error of an obscure or unexpected kind
  6094. will occur.
  6095.  
  6096. Instead  of  being  a  part  of  the normal Tau run-time system, the optimizing
  6097. compiler is invoked as a separate program with an  appropriate  system  command
  6098. (probably  "tc").   When TC starts up it is in a read-eval-print loop and looks
  6099. very much like Tau.  In fact, TC is simply a version of Tau with the  following
  6100. additional definitions available in STANDARD-ENV.
  6101. (COMFILE filespec) -> undefined                                                
  6102.  
  6103.      Compiles   a   file.      For   example,   to  compile  file  fact.t,  say
  6104.      (COMFILE "fact").  TC writes three output files, all having the same  file
  6105.      name as the T source, and distinguished by extension:
  6106.  
  6107.         - The  noise file is a transcript of what TC wrote to the terminal
  6108.           in  the  course  of  the  compilation.    TC  also  writes  some
  6109.           additional statistics and cross-referencing information to noise
  6110.           files.
  6111.  
  6112.         - The support file contains early binding information  useful  for
  6113.           compiling  other files with TC.  See the ENV file header clause,
  6114.           page 102.
  6115.  
  6116.         - The assembly file should be assembled on the target  machine  to
  6117.           get an object file that can be loaded into Tau.
  6118.  
  6119.      The file extensions for the output files depend on the target system.  For
  6120.      MC68000/Aegis, VAX/Unix, and VAX/VMS, the extensions are as follows:
  6121.  
  6122.          System     Architecture          Support    Noise      Assembly  
  6123.          Aegis      68000                 .ams       .amn       .asm       
  6124.          Unix       VAX11                 .uvs       .uvn       .s         
  6125.          VMS        VAX11                 .vvs       .vvn       .mar       
  6126.  
  6127.                                      -103-
  6128.  
  6129.  
  6130. (TC-SYNTAX-TABLE) -> syntax-table                                      Settable
  6131.  
  6132.      This is the basic syntax table from which TC  obtains  macro  definitions.
  6133.      TC  obtains  additional macro definitions from the support environment set
  6134.      up by an (ENV ...)  HERALD clause.  Its default value is the syntax  table
  6135.      of the user environment.
  6136.  
  6137.  
  6138. (TC-MACRO-DEFINITION-ENV) -> environment                               Settable    X10
  6139.  
  6140.      The environment in which macro definition bodies themselves are evaluated,
  6141.      either as a result of encountering  a  DEFINE-LOCAL-SYNTAX  or  LET-SYNTAX
  6142.      expression,  or  by  loading  macro  definitions from a support file.  Its
  6143.      default value is the user environment. [Removed in T>3.]
  6144.  
  6145.                                      -104-
  6146.  
  6147.  
  6148. Chapter 18                                                       User interface
  6149.  
  6150.  
  6151. This chapter describes the user interface to  the  Tau  system,  which  is  the
  6152. current  implementation of the T language.  Also part of the user interface are
  6153. the various debugging facilities, which are described in chapter 19.
  6154.  
  6155. The  features   described   in   this   chapter   are   highly   volatile   and
  6156. implementation-dependent.
  6157.  
  6158. 18.1. Invoking Tau
  6159.  
  6160. To  invoke  a  Tau  system, one typically gives a command to the system command
  6161. processor, as appropriate to  the  operating  system  and  installation.    For
  6162. example, under Aegis, the following interaction might take place:
  6163.  
  6164.     $ t
  6165.     This is MC68000/Aegis Tau version 2.8 (329)
  6166.     ;Loading "~sys/tfix/tfix329.t" into T-IMPLEMENTATION-ENV
  6167.     ;Loading "~init.t" into USER-ENV
  6168.     > (list 'planner 'conniver)
  6169.     (PLANNER CONNIVER)
  6170.     >
  6171.  
  6172. The  interaction may look slightly different in the other implementations.  The
  6173. above illustrates the startup sequence, which proceeds as follows:
  6174.  
  6175.    - The user invokes Tau with an appropriate command.
  6176.  
  6177.    - The  Tau  system  identifies  itself  by  giving  the  processor  and
  6178.      operating  system  under  which it believes itself to be running, the
  6179.      major and minor system version numbers, and the system  edit  number.
  6180.      The  version  numbers  identify which release of Tau is running.  The
  6181.      edit number is useful  to  the  system  implementors  and  should  be
  6182.      provided in any bug reports sent to them.
  6183.  
  6184.    - Tau  loads  a  patch file, if one exists.  The patch file consists of
  6185.      forms which fix bugs in the current release of the system.
  6186.  
  6187.    - Tau loads a user initialization  file,  if  one  exists.    The  user
  6188.      initialization  file  consists  of any forms which the users wants to
  6189.      have evaluated when Tau starts up.  The location in the  file  system
  6190.      where  the  initialization  file is found is system-dependent, but is
  6191.      usually the file init.t in the user's home directory.
  6192.  
  6193.    - Tau  enters  a  read-eval-print  loop.    Read-eval-print  loops  are
  6194.      described in section 18.2.
  6195.  
  6196. (STOP) -> undefined                                                            
  6197.  
  6198.      Exits  Tau in such a way that it may be resumed later.  Control returns to
  6199.      the context from which Tau was invoked.  Under Unix,  this  usually  means
  6200.      the  shell.  Under VMS, this means the command interpreter (DCL).  STOP is
  6201.      not  defined  in  Aegis  Tau  because  the  Aegis  environment  makes   it
  6202.      unnecessary.
  6203.  
  6204.                                      -105-
  6205.  
  6206.  
  6207. (EXIT)                                                                         
  6208.  
  6209.      Exits  Tau,  returning  control to the context in which Tau was invoked in
  6210.      the first place (usually  a  shell  or  other  command  processor).    Any
  6211.      resources  associated  with  the  Tau  process  will be freed; EXIT is not
  6212.      reversible.  A call to EXIT cannot return.
  6213.  
  6214.  
  6215. (COMMAND-LINE) -> list                                                         
  6216.  
  6217.      This function returns the command line used to invoke Tau, represented as 
  6218.      a list of strings.
  6219.  
  6220.  
  6221. 18.2. Read-eval-print loops
  6222.  
  6223. The  user usually interacts with the Tau system via a read-eval-print loop.  As
  6224. illustrated above, this is a command loop which repeatedly reads an expression,
  6225. evaluates it, and prints the value.
  6226.  
  6227. The  read-eval-print  loop  is  a simple command processor; it prints a prompt,
  6228. reads a command from the terminal, executes the command,  then  prints  another
  6229. prompt,  ad  infinitum.   A command is any executable T form, and executing the
  6230. command consists of evaluating the form and printing the result.
  6231. ## -> object                                                                   
  6232.  
  6233.      The variable ** always has as its value the last object which was  printed
  6234.      by  the  read-eval-print  loop,  that is, the value of the last expression
  6235.      typed by the user.
  6236.  
  6237.  
  6238. ++ -> object                                                                   
  6239.  
  6240.      The variable ++ always has as its value the last expression  read  by  the
  6241.      read-eval-print loop.  It is not assigned this value, however, until after
  6242.      the expression has been evaluated, so that a new expression may  refer  to
  6243.      the previous one.
  6244.  
  6245.  
  6246. Expressions  are  read  from  the  terminal  by  applying  the  READ  operation
  6247. (actually, the value of (REPL-READ); see page 108) to the terminal input  port.
  6248. Initially, that   port's read table is the standard read table, but this may be
  6249. changed using SET, for example:
  6250.  
  6251.     (SET (PORT-READ-TABLE (TERMINAL-INPUT)) *MY-READ-TABLE*)
  6252.  
  6253. Evaluation is performed with respect to a particular variable  environment  and
  6254. its syntax table.  The read-eval-print loop may move from place to place within
  6255. the environment hierarchy; one  may  control  the  evaluation  environment  and
  6256. syntax table by setting (REPL-ENV).
  6257. (REPL-ENV) -> environment                                              Settable
  6258.  
  6259.      Accesses  the  environment  passed  to  (REPL-EVAL) by the read-eval-print
  6260.      loop.  Initially, this is the user environment (see page 102).
  6261.  
  6262.                                      -106-
  6263.  
  6264.  
  6265. 18.3. Command levels
  6266.  
  6267. Read-eval-print loops may be  invoked  recursively.    Each  currently  running
  6268. read-eval-print  loop  is said to be at a different command level.  The initial
  6269. read-eval-print loop is at top level, and recursive read-eval-print  loops  are
  6270. at successively deeper levels.
  6271.  
  6272. The  level of the current command loop is reflected in the way the loop prompts
  6273. for input.  At top level, the prompt is a single greater-than  sign  (>).    At
  6274. deeper  command levels, the prompt contains as many greater-than signs as there
  6275. are active read-eval-print loops; for example, >>> if there are  two  recursive
  6276. read-eval-print loops beneath the top level one.
  6277.  
  6278. Deeper  command  levels  are usually entered as the result of program execution
  6279. errors, but may also be entered because of a keyboard interrupt or an  explicit
  6280. call to BREAKPOINT.
  6281.  
  6282. Interrupts:        Issuing  a  keyboard  interrupt  will asynchronously enter a
  6283. read-eval-print loop.  One may proceed from this breakpoint, at the point where
  6284. computation  was interrupted, by doing (RET).  Keyboard interrupts are normally
  6285. issued under Aegis by giving a Display Manager DQ command (normally assigned to
  6286. control-Q),  under  VMS  by  typing  control-C,  or  under  Unix  by typing the
  6287. interrupt character (normally control-C or DEL).
  6288.  
  6289. End-of-file:   An end-of-file condition on the terminal input port which occurs
  6290. at a read-eval-print loop will cause control to transfer up   one command level
  6291. to the next read-eval-print loop.  End-of-file can usually be
  6292. generated  under  Aegis with the display manager EEF command (normally assigned
  6293. to control-Z), under VMS by typing control-Z, or under Unix by typing  the  end
  6294. of file character (normally control-D).
  6295. (RESET)                                                                        
  6296.  
  6297.      Transfers  control  directly  to  the  top-level  read-eval-print  loop by
  6298.      performing a throw.
  6299.  
  6300.  
  6301. (RET)                                                                              X5
  6302. (RET object)
  6303.  
  6304.      Returns object (which defaults to an undefined value if not  supplied)  as
  6305.      the  value  of  the  current  read-eval-print  loop.  See section 19.1 for
  6306.      examples.
  6307.  
  6308.  
  6309. (BREAKPOINT . message) -> object or undefined                                  
  6310.  
  6311.      Enters a read-eval-print loop.  If message is not null, then it is printed
  6312.      by  DISPLAY on the (ERROR-OUTPUT)   port.  If (RET object) is called, then
  6313.      the loop terminates and object is returned as the value  of  the  call  to
  6314.      BREAKPOINT.  If an end-of-file condition occurs, then control is thrown to
  6315.      the read-eval-print loop at the next higher level, which continues.
  6316.  
  6317.  
  6318. 18.4. Transcripts
  6319.  
  6320. A transcript is  a  record  of  the  user's  interaction  with  the  T  system.
  6321. Transcripts are necessary in T implementations under operating systems which do
  6322. not natively provide transcript facilities.  Transcripts are not necessary, for
  6323. example, when running under the Aegis Display Manager.
  6324.  
  6325.                                      -107-
  6326.  
  6327.  
  6328. (TRANSCRIPT-ON filename) -> undefined                                          
  6329.  
  6330.      Starts  writing  a  transcript  to  the  specified  file.    All output to
  6331.      (TERMINAL-OUTPUT)  and  input  from  (TERMINAL-INPUT)  between  calls   to
  6332.      TRANSCRIPT-ON  and  TRANSCRIPT-OFF  is  written to the file.  A subsequent
  6333.      call to TRANSCRIPT-OFF will terminate the transcript, closing the file.
  6334.  
  6335.  
  6336. (TRANSCRIPT-OFF) -> undefined                                                  
  6337.  
  6338.      Closes the active transcript file.
  6339.  
  6340.  
  6341. 18.5. Customization
  6342.  
  6343. The various phases of the read-eval-print loop may be customized  by  assigning
  6344. values to switches.
  6345. (REPL-READ) -> procedure                                               Settable
  6346.  
  6347.      Accesses  the  READ  part of the read-eval-print loop.  Initially, this is
  6348.      READ.
  6349. (REPL-EVAL) -> procedure                                               Settable
  6350.  
  6351.      Accesses the EVAL part of the read-eval-print loop.   Initially,  this  is
  6352.      EVAL.
  6353.  
  6354.  
  6355. (REPL-PRINT) -> procedure                                              Settable
  6356.  
  6357.      Accesses  the  PRINT part of the read-eval-print loop.  Initially, this is
  6358.      PRINT.
  6359.  
  6360.  
  6361. (REPL-PROMPT) -> procedure                                             Settable
  6362.  
  6363.      Accesses the prompting routine used in the  read-eval-print  loop.    This
  6364.      should  be  a  procedure  of  one argument, which is a nonnegative integer
  6365.      giving the command level (zero at top level, one at the next deeper level,
  6366.      and   so  on).    The  procedure  should  return  a  string.    Initially,
  6367.      (REPL-PROMPT) is a procedure that returns "> " at the top level, ">> "  at
  6368.      the level below that, etc.
  6369.  
  6370.  
  6371. (LOAD-NOISILY?) -> boolean                                             Settable
  6372.  
  6373.      If  (LOAD-NOISILY?) is true (which it is initially), then LOAD and REQUIRE
  6374.      will print the value of each top-level expression in  the  file  (standard
  6375.      compiler only).  The output goes to the terminal output   port.
  6376.  
  6377.  
  6378. (REPL-WONT-PRINT? object) -> boolean                                  Operation
  6379.  
  6380.      Read-eval-print loops will not print any object which answers true to this
  6381.      operation.  Note that this  is  unrelated  to  the  functioning  of  PRINT
  6382.      itself.
  6383.  
  6384.                                      -108-
  6385.  
  6386.  
  6387. REPL-WONT-PRINT -> object                                                    
  6388.  
  6389.      This  has  as  value  an object which answers true to the REPL-WONT-PRINT?
  6390.      predicate.
  6391.  
  6392.          REPL-WONT-PRINT  <=>  (OBJECT NIL ((REPL-WONT-PRINT? SELF) T))
  6393.  
  6394.  
  6395.  
  6396. Chapter 19                                                            Debugging
  6397.  
  6398.  
  6399. The facilities described in this chapter  are  highly  implementation-specific,
  6400. and  subject  to change without notice.  Facilities described here are intended
  6401. either for use directly as commands, or as utilities for user-written debugging
  6402. subsystems.
  6403.  
  6404. 19.1. Errors
  6405.  
  6406. When  the implementation detects an error condition, a message is printed and a
  6407. read-eval-print loop is entered in the  dynamic  context  in  which  the  error
  6408. occurred.  A number of facilities are available at this point for debugging and
  6409. for recovering from the error.
  6410.  
  6411. Errors are usually detected in conditions  which  are  left  undefined  by  the
  6412. manual (see sections 2.4 and 13.2).  These conditions include the following:
  6413.  
  6414.    - An unbound variable is referenced.
  6415.  
  6416.    - A procedure is called with too few or too many arguments.
  6417.  
  6418.    - A non-procedure is called.
  6419.  
  6420.    - An object of the wrong type is passed to a system procedure.
  6421.  
  6422.    - A string or vector index is out of range.
  6423.  
  6424.    - A  generic operation is invoked on an object with no method to handle
  6425.      it.
  6426.  
  6427.    - The external representation of an object being parsed by  READ-OBJECT
  6428.      or  a  read macro is syntactically incorrect.  (This kind of error is
  6429.      called a read error.)
  6430.  
  6431.    - An object being interpreted as an expression by a compiler or a macro
  6432.      expander is syntactically incorrect.  (This kind of error is called a
  6433.      syntax error.)
  6434.  
  6435.    - A call to ERROR or UNDEFINED-EFFECT occurs.  
  6436.  
  6437. Once inside the read-eval-print loop, one may examine the  current  environment
  6438. (e.g.,  examining  variables  or  the  stack)  using  the  read-eval-print loop
  6439. (section 18.2) or the inspector (section 19.3).
  6440.  
  6441.                                      -109-
  6442.  
  6443.  
  6444. Typical actions after an error occurs include:
  6445.  
  6446.    - The user corrects the error by returning a new value with RET.
  6447.  
  6448.    - The user  goes  up  one  command  level  by  typing  the  end-of-file
  6449.      character (see page 108).
  6450.  
  6451.    - The user throws to top level by calling (RESET) (page 108).
  6452.  
  6453. Example:
  6454.  
  6455.     > (CADR 3)
  6456.  
  6457.     ** Error: attempting to take CADR of 3
  6458.     >> (RET '(A B))
  6459.     B
  6460.     > (PLUS 3 4)
  6461.  
  6462.     ** Error: variable PLUS has no value
  6463.     >> (RET ADD)
  6464.     7
  6465.  
  6466. (RECKLESSNESS) -> LOW, MEDIUM, or HIGH                                 Settable
  6467.  
  6468.      Doing  (SET  (RECKLESSNESS) 'HIGH) will improve performance at the expense
  6469.      of error-checking.  Specifically, somewhere between 10 and 25 instructions
  6470.      will  be  elided  from most procedure calls, but wrong-number-of-argument,
  6471.      undefined-procedure, and object-not-applicable errors will probably  cause
  6472.      illegal   memory   references  or  odd  address  errors  instead  of  more
  6473.      comprehensible error reports.
  6474.  
  6475.  
  6476. 19.2. Debugging utilities
  6477.  
  6478. (TRACE variable) -> undefined                                      Special form
  6479.  
  6480.      Reassigns variable, whose value  should  be  a  procedure,  to  be  a  new
  6481.      procedure  which  prints information on the (DEBUG-OUTPUT)   port whenever
  6482.      it is called or returns a value.
  6483.  
  6484.  
  6485. (UNTRACE variable) -> undefined                                    Special form
  6486.  
  6487.      If variable has a traced procedure as its value, UNTRACE  restores  it  to
  6488.      its original value.  Otherwise it prints a warning and does nothing.
  6489.  
  6490.  
  6491. (PP procedure) -> undefined                                        Special form
  6492.  
  6493.      Prints  the definition of procedure on the terminal output   port.  If the
  6494.      source code is not available, then it prints the name of a file  where  it
  6495.      can  be  found.   (See also PRETTY-PRINT, page 91, and WHERE-DEFINED, page
  6496.      113.)
  6497.  
  6498.  
  6499. (BACKTRACE) -> undefined                                                       
  6500.  
  6501.      Prints a one-line summary describing each continuation on the stack.   See
  6502.      also DEBUG, page 111.
  6503.  
  6504.                                      -110-
  6505.  
  6506.  
  6507. 19.3. The inspector
  6508.  
  6509. CRAWL,  also  known  as  the inspector, is a stack and structure inspector.  It
  6510. consists of a command loop and a set of commands.  The inspector keeps track of
  6511. a  current  object,  and  a stack of objects which have previously been current
  6512. objects.  Some inspector commands move from one object to another.
  6513.  
  6514. The command loop operates as follows: the current object is "summarized"  (that
  6515. is, printed or displayed somehow); a prompt is printed; a line is read; and any
  6516. commands on the line are executed.  One can give one  or  more  commands  on  a
  6517. single input line.
  6518.  
  6519. The  current  object may be any object.  If it is a continuation (stack frame),
  6520. the name of the procedure which contains the  continuation's  return  point  is
  6521. printed, and the prompt is "debug:".  Otherwise, the object is printed (up to a
  6522. maximum of one line of output), and the prompt is "crawl:".
  6523.  
  6524. The meanings of some commands vary depending on what kind of object the current
  6525. object is, and not all commands are appropriate for all kinds of objects.
  6526. (DEBUG) -> undefined                                                           
  6527.  
  6528.      (DEBUG)  enters  the inspector.  The current object becomes a continuation
  6529.      near the top of the stack (more precisely, the continuation to  which  the
  6530.      value passed to RET will be given).
  6531.  
  6532.  
  6533. (CRAWL object) -> undefined                                                    
  6534.  
  6535.      Enters the inspector.  The current object becomes object.
  6536.  
  6537.  
  6538. Inspector commands:
  6539.  
  6540. ?               Help:  prints  a  list  of  inspector  commands,  with one-line
  6541.                 summaries.
  6542.  
  6543. Q               Quit:  exits  out  of  the  inspector,  usually  back  to   the
  6544.                 read-eval-print loop.
  6545.  
  6546. U               Up:  pops  the  stack  of saved objects.  The current object is
  6547.                 forgotten, and the inspector  moves  to  the  previous  current
  6548.                 object.
  6549.  
  6550. D               Down:  if  the  current  object is a continuation, moves to the
  6551.                 next  continuation  deeper  in  the  stack,  that  is,  to  the
  6552.                 continuation that was pushed prior to the current continuation.
  6553.  
  6554. X               Exhibit:  prints  useful  information about the current object.
  6555.                 The exact behavior of this varies depending on the type of  the
  6556.                 object.   For structures, all of the structure's components are
  6557.                 displayed.  For continuations, any saved  values  are  printed.
  6558.                 Integers are printed in various radices.
  6559.  
  6560.                 For  some  kinds of object, such as structures and vectors, the
  6561.                 contents of an object will be displayed in a menu  form,  as  a
  6562.                 sequence of lines of the form "[key] component".  In this case,
  6563.                 giving key as an inspector  command  will  move  to  component,
  6564.                 which then becomes the current object.
  6565.  
  6566.                                      -111-
  6567.  
  6568.  
  6569. integer         Select  element: in the case of a list or vector, this moves to
  6570.                 the appropriate component.  For example, if the current  object
  6571.                 is  a  list,  then  3  as an inspector command is the same as A
  6572.                 CADDDR:  it moves to the list's fourth element.
  6573.  
  6574. selector        Select component: if the current object is a structure,  typing
  6575.                 a selector name will move to that component of the structure.
  6576.  
  6577. B               Breakpoint:  enters  a  read-eval-print  loop.  Executing (RET)
  6578.                 will return back into the inspector.  The read-eval-print  loop
  6579.                 will execute either in (REPL-ENV), or, if the current object is
  6580.                 a continuation or procedure created by interpreted  code  (i.e.
  6581.                 code  compiled  by the standard compiler, as opposed to TC), in
  6582.                 the lexical environment of the object.  Inside  the  breakpoint
  6583.                 loop, the system variable *OBJ* is bound to the current object.
  6584.  
  6585. C               Crawl:  moves  to  a  new  object.    The object is obtained by
  6586.                 evaluating an input expression, which is read either  from  the
  6587.                 command  line  or  in response to a prompt.  The environment of
  6588.                 the evaluation is one appropriate to  the  current  object,  as
  6589.                 with the B command.
  6590.  
  6591. E               Evaluate:  evaluates an expression.  The expression is read and
  6592.                 evaluated as with the C command.  The result of the  evaluation
  6593.                 is printed, but the current object remains the same.
  6594.  
  6595. A               Apply:  applies  a procedure to the current object, and move to
  6596.                 the result of that call.    An  expression  evaluating  to  the
  6597.                 procedure is read as with the C command.
  6598.  
  6599. M               Macroexpand:  performs  one  macro  expansion  on  the  current
  6600.                 object, which should be a list, and the current object  becomes
  6601.                 the result of the macro expansion.
  6602.  
  6603. P               Pretty-print:  prints  the  current  object  using  the  pretty
  6604.                 printer.  If the current object is a  continuation,  then  this
  6605.                 command  tries  to  print  the  expression  to  which the value
  6606.                 returned by the continuation is to be supplied.
  6607.  
  6608. R               Return: if the current object  is  a  continuation,  returns  a
  6609.                 value  to  it.    The value is obtained as with the C, E, and A
  6610.                 commands.
  6611.  
  6612. W               Where-defined: prints the result of  calling  WHERE-DEFINED  on
  6613.                 the current object.
  6614.  
  6615. V               Unit: moves to a template's or procedure's unit.  Units are not
  6616.                 documented, but the X command works with them.  This command is
  6617.                 intended primarily for the use of the Tau implementors.
  6618.  
  6619. The  control stack which one inspects by invoking the inspector with (DEBUG) is
  6620. a sequence of continuations, or stack frames.   These  differ  from  activation
  6621. records  in  implementations  of  languages  such  as  C  or  Lisp in that they
  6622. represent future computations rather than past calls.  A full call  history  is
  6623. not  easily available in tail-recursive languages such a T and Scheme.  This is
  6624. implementation-dependent, of course, and future T implementations may  maintain
  6625. call histories for debugging purposes.
  6626.  
  6627.                                      -112-
  6628.  
  6629.  
  6630. Each  continuation  represents a control point which will make use of the value
  6631. returned to the continuation.  Usually these control points correspond  to  the
  6632. arguments  in  a  call,  the  predicate  in  an IF or COND, or any but the last
  6633. subform of a block.  For example, when evaluating a  call,  a  continuation  is
  6634. constructed  for  each  argument in the call, because these values will be used
  6635. when the call actually occurs.  In the example below,  the  continuations  into
  6636. FACT  were mostly delivering values to the second argument position in the call
  6637. to *.
  6638.  
  6639. The three-column synopsis that the inspector prints for  continuations  is  the
  6640. same  as  that printed by BACKTRACE (page 110). The first column is the name of
  6641. the procedure into which control will return, or (anonymous)  if  no  procedure
  6642. name   is   available   (as  for  procedures  created  by  anonymous  top-level
  6643. LAMBDA-expressions instead of by DEFINE).  The second column is the name of the
  6644. source  file  containing the procedure, and the third column is relevant source
  6645. code, if available.
  6646.  
  6647. Here is a sample interaction with the inspector.  Commentary is in  Roman  font
  6648. on  the  right.   The terms "frame," "stack frame," and "continuation" are used
  6649. interchangeably.
  6650.  
  6651.     > (define (fact n)                      Define factorial function.
  6652.         (cond ((= n 0) i)                   Bug: i instead of 1.
  6653.               (else (* n (fact (- n 1))))))
  6654.     #{Procedure 120 FACT}
  6655.     > (fact 4)
  6656.  
  6657.     ** Error: variable I is unbound         Error detected by interpreter.
  6658.     >> (debug)
  6659.     #{Continuation 121}                     Current object is this frame.
  6660.      BIND-INTERNAL         THROW            Internal to the implementation.
  6661.     debug: d                                Go down one frame.
  6662.     #{Dynamic-state-transition 122}         Also internal, keep going.
  6663.     debug: d
  6664.     #{Continuation 123}
  6665.      FACT                  ()         I     Okay, this looks good.
  6666.     debug: d
  6667.     #{Continuation 124}
  6668.      FACT                  ()         (* N (FACT (- N 1)))
  6669.     debug: e n                              Evaluate N in this frame.
  6670.     1                                       Value is 1.
  6671.     debug: d
  6672.     #{Continuation 125}
  6673.      FACT                  ()         (* N (FACT (- N 1)))
  6674.     debug: e n                              Value is 2 in this frame.
  6675.     2
  6676.     debug: d d                              Go down two frames.
  6677.     #{Continuation 126}
  6678.      FACT                  ()         (* N (FACT (- N 1)))
  6679.     debug: d
  6680.     #{Continuation 127}
  6681.      READ-EVAL-PRINT-LOOP  REPL             FACT's caller (i.e. top level).
  6682.     debug: u u u u u                        Up five frames.
  6683.     #{Continuation 123}
  6684.      FACT                  ()         I
  6685.     debug: r 1                              Return the value 1 to this fram
  6686.     24                                      Execution proceeds, and the val
  6687.     >                                       24 comes out.
  6688.  
  6689.                                      -113-
  6690.  
  6691.  
  6692. 19.4. Debugging primitives
  6693.  
  6694. This section describes routines which may be useful in writing debugging  aids.
  6695. Note that they are not part of the language, and therefore should be avoided in
  6696. "ordinary" programs.  Relying on these routines  may  lead  to  programs  which
  6697. behave  differently  depending on how the programs are compiled (TC or standard
  6698. compiler), or which fail to work across releases.
  6699. (WHERE-DEFINED object) -> filename                                    Operation
  6700.  
  6701.      Tries to find a filename for the source file  wherein  object  (usually  a
  6702.      procedure) is defined.
  6703.  
  6704.  
  6705. (IDENTIFICATION object) -> symbol or false                            Operation
  6706.  
  6707.      If  appropriate,  this  returns  a symbol naming a variable which, in some
  6708.      environment, might be defined to be the object.  If no such identification
  6709.      is appropriate, IDENTIFICATION returns false.  This behavior is heuristic,
  6710.      not contractual;  for  no  value  is  IDENTIFICATION  required  to  return
  6711.      non-null.
  6712.  
  6713.          (IDENTIFICATION CADR)                =>  CADR
  6714.          (LET ((X CADR)) (IDENTIFICATION X))  =>  CADR
  6715.  
  6716.  
  6717. (ARGSPECTRUM procedure) -> pair                                       Operation
  6718.  
  6719.      Returns   an  argspectrum  for  procedure.    An  argspectrum  is  a  pair
  6720.      (min . max) which describes the number of arguments that procedure expects
  6721.      to  receive  when  called.    Min  is always an integer giving the minimum
  6722.      number of arguments expected; max is either an integer giving  a  maximum,
  6723.      or  it is (), meaning that exactly min arguments are required, or it is T,
  6724.      meaning that any number of arguments (but at least min) are acceptable.
  6725.  
  6726.  
  6727. (DISCLOSE procedure) -> list or false                                          
  6728.  
  6729.      Attempts to reconstruct a source expression from which procedure may  have
  6730.      been  compiled.    This  may  work  for  code  compiled using the standard
  6731.      compiler, but is likely to fail  to  work  for  code  compiled  using  TC.
  6732.      Returns false if no source code can be obtained.
  6733.  
  6734.  
  6735. (GET-ENVIRONMENT procedure) -> environment or false                            
  6736.  
  6737.      Attempts  to  reconstruct  an environment in which procedure may have been
  6738.      loaded (or run).  This may work  for  code  compiled  using  the  standard
  6739.      compiler,  but  is  likely  to  fail  to  work for code compiled using TC.
  6740.      Returns false if no environment can be obtained.
  6741.  
  6742.  
  6743. (STRUCTURE-TYPE object) -> stype or false                                      
  6744.  
  6745.      If object is a structure, this returns the structure type of which  it  is
  6746.      an   instance.     If  object  is  not  a  structure,  it  returns  false.
  6747.      STRUCTURE-TYPE is to be used with care  since  it  may  violate  the  data
  6748.      protection  otherwise provided by structure types.  That is, anyone who is
  6749.      given a structure may find out about its internals.
  6750.  
  6751.                                      -114-
  6752.  
  6753.  
  6754. (WALK-SYMBOLS procedure) -> undefined                                          
  6755.  
  6756.      Calls procedure on every accessible symbol.
  6757.  
  6758.  
  6759. 19.5. Miscellaneous
  6760.  
  6761. [(ENFORCE predicate value) -> value
  6762.  
  6763.     If (predicate value) returns false, ENFORCE enters a breakpoint loop  which
  6764.     can then be used to return another value via (RET newvalue). [T>3]]
  6765.  
  6766. T-VERSION-NUMBER -> integer                                                  
  6767.  
  6768.      An integer which gives the version  number  of  the  currently  running  T
  6769.      implementation.  The integer has the form
  6770.  
  6771.          (+ (* major-version-number 1000) minor-version-number)
  6772.  
  6773.      For  example,  in  Tau  2.7, T-VERSION-NUMBER   is 2007.  Knowledge of the
  6774.      version number may be useful in dealing with incompatibilities between Tau
  6775.      releases,  so that programs may conditionally adjust their state according
  6776.      to the version, and thus be able to run in both older and newer  releases.
  6777.  
  6778.  
  6779. T-IMPLEMENTATION-ENV -> locale                                               
  6780.  
  6781.      This environment contains variables internal to the implementation of T.
  6782.          (IMPORT T-IMPLEMENTATION-ENV %%PAIR-TAG)
  6783.  
  6784.  
  6785. TC-ENV -> locale                                                             
  6786.  
  6787.      This  environment contains variables internal to the implementation of TC.
  6788.  
  6789.  
  6790. (GC) -> undefined                                                              
  6791.  
  6792.      Invokes the garbage collector.  Garbage collection is a low-level  process
  6793.      by  which  the  memory  used  by objects which are no longer accessible is
  6794.      reclaimed for use by new  objects.    Ordinarily,  garbage  collection  is
  6795.      invoked  asynchronously  as  the  need arises, so explicit calls to GC are
  6796.      unnecessary. A side-effect of garbage collection is that any ports created
  6797.      by OPEN which are both inaccessible and still open, are closed. Cf. 13.8.
  6798.  
  6799. (GC-STATS) -> undefined                                                        
  6800.  
  6801.      Prints some statistics about the most recent garbage collection.
  6802.  
  6803.  
  6804. (GC-NOISILY?) -> boolean                                               Settable
  6805.  
  6806.      Switch,  initially  true.   If true, then the garbage collector will print
  6807.      messages when invoked.  If false, it will do its work silently.
  6808.  
  6809.                                      -115-
  6810.  
  6811.  
  6812. Appendix A                                            A meta-circular evaluator
  6813.  
  6814.  
  6815. This appendix gives an annotated listing of an evaluator for T. This  evaluator
  6816. is  written  in  T  (thus  the  adjective "meta-circular," since it employs the
  6817. notation it tries to describe) and  attempts  to  continue  in  the  spirit  of
  6818.  [STEELE78ART]  and [MCCARTHY60].  It represents an attempt, short of writing a
  6819. denotational semantics, to provide a  moderately  precise  description  of  T's
  6820. semantics.
  6821.  
  6822. This  interpreter should also be of some interest simply as an extended example
  6823. of a program written in T.
  6824.  
  6825. It is important to know what this evaluator is not:
  6826.  
  6827.    - It is not efficient.  It expressly makes  no  effort  at  all  to  do
  6828.      things in clever or efficient ways.
  6829.  
  6830.    - It  is  not  complete.   It tries to define most of the special forms
  6831.      that it uses, but does not define any primitive  procedures  such  as
  6832.      CAR or APPLY.  However, any special forms that have been omitted are,
  6833.      for the most part, trivially definable in terms of the special  forms
  6834.      here  defined,  as  source-to-source transformations; in fact this is
  6835.      the how the existing implementation works.
  6836.  
  6837.    - It is not parameterized (that is, extensible).  No means  of  passing
  6838.      in  syntax  tables  or adding syntactic extensions (DEFINE-SYNTAX) is
  6839.      provided.
  6840.  
  6841.    - It makes no attempt to detect or deal with error conditions, such  as
  6842.      unevaluable  expressions,  unbound  variables,  or  wrong  number  of
  6843.      arguments in calls.
  6844.  
  6845. EVALUATE, the universal function, computes the value  of  an  expression  in  a
  6846. given variable environment.  It dispatches to a specialist routine on the basis
  6847. of the syntax of the expression.
  6848.  
  6849.     (DEFINE (EVALUATE EXP ENV)
  6850.       (COND ((SYMBOL? EXP)
  6851.              (VALUE EXP ENV))
  6852.             ((OR (NUMBER? EXP)
  6853.                  (CHARACTER? EXP)
  6854.                  (STRING? EXP))
  6855.              EXP)
  6856.             ((PAIR? EXP)
  6857.              (CASE (CAR EXP)
  6858.                ((QUOTE)    (EVALUATE-QUOTE    EXP ENV))
  6859.                ((IF)       (EVALUATE-IF       EXP ENV))
  6860.                ((BLOCK)    (EVALUATE-BLOCK    EXP ENV))
  6861.                ((LAMBDA)   (EVALUATE-LAMBDA   EXP ENV))
  6862.                ((DEFINE)   (EVALUATE-DEFINE   EXP ENV))
  6863.                ((LSET)     (EVALUATE-LSET     EXP ENV))
  6864.                ((SET)      (EVALUATE-SET      EXP ENV))
  6865.                ((OBJECT)   (EVALUATE-OBJECT   EXP ENV))
  6866.                ((LOCALE)   (EVALUATE-LOCALE   EXP ENV))
  6867.                ((LOCATIVE) (EVALUATE-LOCATIVE EXP ENV))
  6868.                ((COND)     (EVALUATE-COND     EXP ENV))
  6869.                ((AND)      (EVALUATE-AND      EXP ENV))
  6870.                ((OR)       (EVALUATE-OR       EXP ENV))
  6871.                ((LET)      (EVALUATE-LET      EXP ENV))
  6872.                (ELSE       (EVALUATE-CALL     EXP ENV))))))
  6873.  
  6874.                                      -116-
  6875.  
  6876.  
  6877. EVALUATE-CALL computes the value of a call to a procedure.  The  procedure  and
  6878. arguments  are  evaluated recursively, and the procedure is invoked using APPLY
  6879. (assumed to be primitive; not defined by this Appendix).
  6880.  
  6881.     (DEFINE (EVALUATE-CALL EXP ENV)
  6882.       (APPLY (EVALUATE (CAR EXP) ENV)
  6883.              (MAP (LAMBDA (ARG) (EVALUATE ARG ENV))
  6884.                   (CDR EXP))))
  6885.  
  6886. QUOTE, IF, and BLOCK have straightforward definitions.
  6887.  
  6888.     (DEFINE (EVALUATE-QUOTE EXP ENV)
  6889.       (CADR EXP))
  6890.  
  6891.     (DEFINE (EVALUATE-IF EXP ENV)
  6892.       (IF (EVALUATE (CADR EXP) ENV)
  6893.           (EVALUATE (CADDR EXP) ENV)
  6894.           (EVALUATE (CADDDR EXP) ENV)))
  6895.  
  6896.     (DEFINE (EVALUATE-BLOCK EXP ENV)
  6897.       (EVALUATE-SEQUENCE (CDR EXP) ENV))
  6898.  
  6899. EVALUATE-SEQUENCE is an auxiliary routine called in several places.   It  needs
  6900. to  be  careful to maintain tail-recursive semantics; thus the loop termination
  6901. when (NULL? (CDR EXPS)) instead of the more obvious (NULL? EXPS).
  6902.  
  6903.     (DEFINE (EVALUATE-SEQUENCE EXPS ENV)
  6904.       (COND ((NULL? (CDR EXPS))
  6905.              (EVALUATE (CAR EXPS) ENV))
  6906.             (ELSE
  6907.              (EVALUATE (CAR EXPS) ENV)
  6908.              (EVALUATE-SEQUENCE (CDR EXPS) ENV))))
  6909.  
  6910. Surprisingly, EVALUATE-LAMBDA has a very straightforward definition in terms of
  6911. LAMBDA:  it  simply  returns  a  procedure  which  evaluates  the  body  of the
  6912. lambda-expression in an appropriately augmented variable environment.
  6913.  
  6914.     (DEFINE (EVALUATE-LAMBDA EXP ENV)
  6915.       (LAMBDA ARGS
  6916.         (EVALUATE-SEQUENCE (CDDR EXP)
  6917.                            (BIND-VARIABLES (CADR EXP) ARGS ENV))))
  6918.  
  6919. SET has two  cases;  whereas  assignment  to  a  variable  must  be  primitive,
  6920. assignment  to  a  generalized  "place" is performed using a simple source-code
  6921. rewrite.
  6922.  
  6923.     (DEFINE (EVALUATE-SET EXP ENV)
  6924.       (LET ((PLACE (CADR EXP)))
  6925.         (COND ((ATOM? PLACE)
  6926.                (SET-VALUE PLACE ENV (EVALUATE (CADDR EXP) ENV) NIL))
  6927.               (ELSE
  6928.                (EVALUATE `((SETTER ,(CAR PLACE)) ,@(CDR PLACE) ,(CADDR EXP)
  6929.                          ENV)))))
  6930.  
  6931. (SET variable value) and (LSET variable value) are interpreted in  exactly  the
  6932. same  way,  except for the fourth argument passed to SET-VALUE, which is a flag
  6933. to be eventually passed to  ENV-LOOKUP;  this  determines  whether  the  lookup
  6934. proceeds outwards past the innermost locale, or stops there, where the variable
  6935. is either replaced or inserted in the environment.  DEFINE is the same as LSET,
  6936. but permits extended syntax for defining procedures.
  6937.  
  6938.                                      -117-
  6939.  
  6940.  
  6941.     (DEFINE (EVALUATE-LSET EXP ENV)
  6942.       (SET-VALUE (CADR EXP) ENV (EVALUATE (CADDR EXP) ENV) T))
  6943.  
  6944.     (DEFINE (EVALUATE-DEFINE EXP ENV)
  6945.       (LET ((PATTERN (CADR EXP)))
  6946.         (COND ((ATOM? PATTERN)
  6947.                (EVALUATE-LSET EXP ENV))
  6948.               (ELSE
  6949.                (EVALUATE-LSET `(LSET ,(CAR PATTERN)
  6950.                                      (LAMBDA ,(CDR PATTERN) ,@(CDDR EXP)))
  6951.                               ENV)))))
  6952.  
  6953. The  evaluator  implements  OBJECT  using JOIN by iteratively constructing, one
  6954. method-clause at a time, an object which will have the requisite behavior.  The
  6955. auxiliary routine EVALUATE-OBJECT-AUX could have been defined using LABELS, but
  6956. the code would have become too  deeply  indented,  exacerbating  this  manual's
  6957. already forbidding formatting problems.
  6958.  
  6959.     (DEFINE (EVALUATE-OBJECT EXP ENV)
  6960.       (EVALUATE-OBJECT-AUX (EVALUATE (CADR EXP) ENV) (CDDR EXP) ENV))
  6961.  
  6962.     (DEFINE (EVALUATE-OBJECT-AUX PROC CLAUSES ENV)
  6963.       (COND ((NULL? CLAUSES)
  6964.              (OBJECT PROC))
  6965.             (ELSE
  6966.              (LET ((CLAUSE (CAR CLAUSES)))
  6967.                (JOIN (OBJECT PROC
  6968.                              (((EVALUATE (CAAR CLAUSE) ENV) SELF . ARGS)
  6969.                               (EVALUATE-SEQUENCE (CDR CLAUSE)
  6970.                                                  (BIND-VARIABLES (CDAR CLAU
  6971.                                                                  (CONS SELF
  6972.                                                                  ENV))))
  6973.                      (EVALUATE-OBJECT-AUX NIL (CDR CLAUSES) ENV))))))
  6974.  
  6975. As described elsewhere in this manual, a locale is an environment whose list of
  6976. bound variables can be mutated, in a controlled way,  as  a  side-effect.    To
  6977. accomplish  this, LOCALE is implemented using a local variable THE-ENV which is
  6978. assigned new values (using a SET side-effect) as new variables are added to the
  6979. environment.    This  happens  whenever a locative for a variable is needed and
  6980. cannot be located, either because the enclosing environment has no binding  for
  6981. the  variable  or  because  the  LOCAL?  argument to ENV-LOOKUP is true and the
  6982. lookup must stop at the level of the locale.
  6983.  
  6984. The actual locale object has a trivial definition  for  the  ENV-LOOKUP  method
  6985. which jumps directly to whatever the current value of THE-ENV happens to be.
  6986.  
  6987.     (DEFINE (EVALUATE-LOCALE EXP ENV)
  6988.       (LET ((THE-ENV NIL))
  6989.         (SET THE-ENV
  6990.              (OBJECT NIL
  6991.                      ((ENV-LOOKUP SELF ID LOCAL? CREATE?)
  6992.                       (COND ((AND LOCAL? (NOT CREATE?))
  6993.                              NIL)
  6994.                             ((AND (NOT LOCAL?)
  6995.                                   (ENV-LOOKUP ENV ID NIL NIL)))
  6996.                             (CREATE?
  6997.                              (SET THE-ENV
  6998.                                   (BIND-VARIABLE ID (UNDEFINED-VALUE) THE-E
  6999.                              (ENV-LOOKUP THE-ENV ID LOCAL? CREATE?))
  7000.                             (ELSE NIL)))))
  7001.  
  7002.                                      -118-
  7003.  
  7004.  
  7005.         (LET ((THE-LOCALE
  7006.                (OBJECT NIL
  7007.                        ((ENV-LOOKUP SELF ID LOCAL? CREATE?)
  7008.                         (ENV-LOOKUP THE-ENV ID LOCAL? CREATE?)))))
  7009.           (IF (CADR EXP) (SET-VALUE (CADR EXP) THE-LOCALE THE-LOCALE T))
  7010.           (EVALUATE-SEQUENCE (CDDR EXP) THE-LOCALE))))
  7011.  
  7012. Environments  are represented as objects which handle the ENV-LOOKUP operation.
  7013. When a procedure created by LAMBDA is called, BIND-VARIABLES is called to build
  7014. up  a  new environment structure, one variable at a time.  This is analogous to
  7015. the association-list technique used in [STEELE78ART]  and [MCCARTHY60],  except
  7016. that  the  environment  is  represented  not  by  list structure but by chained
  7017. closure (i.e. object) structure.  (Compare  this  with  the  code  for  dynamic
  7018. binding in [STEELE76IMP], section 3.2.2.)
  7019.  
  7020. BIND-VARIABLES  is  a  simple  recursion  over  the  lists of formal and actual
  7021. parameters, calling BIND-VARIABLE for each variable which needs  to  be  bound.
  7022. If  the  list  of  formals is an improper list then the identifier which is its
  7023. last cdr must be bound to a list of the rest of the arguments.
  7024.  
  7025.     (DEFINE (BIND-VARIABLES FORMALS ACTUALS ENV)
  7026.       (COND ((PAIR? FORMALS)
  7027.              (BIND-VARIABLE (CAR FORMALS)
  7028.                             (CAR ACTUALS)
  7029.                             (BIND-VARIABLES (CDR FORMALS)
  7030.                                             (CDR ACTUALS)
  7031.                                             ENV)))
  7032.             ((NULL? FORMALS)
  7033.              ENV)
  7034.             (ELSE
  7035.              (BIND-VARIABLE FORMALS ACTUALS ENV))))
  7036.  
  7037.     (DEFINE (BIND-VARIABLE IDENTIFIER VALUE ENV)
  7038.       (OBJECT NIL
  7039.               ((ENV-LOOKUP SELF ID LOCAL? CREATE?)
  7040.                (COND ((EQ? ID IDENTIFIER)
  7041.                       (LOCATIVE VALUE))
  7042.                      (ELSE
  7043.                       (ENV-LOOKUP ENV ID LOCAL? CREATE?))))))
  7044.  
  7045. Fetching and storing the value of a variable is  accomplished  by  obtaining  a
  7046. locative  to  the  variable  using  the  ENV-LOOKUP  operation, and then either
  7047. examining or depositing into the locative.
  7048.  
  7049.     (DEFINE (VALUE ID ENV)
  7050.       (CONTENTS (ENV-LOOKUP ENV ID NIL NIL)))
  7051.  
  7052.     (DEFINE (SET-VALUE ID ENV VAL LOCAL?)
  7053.       (SET (CONTENTS (ENV-LOOKUP ENV ID LOCAL? T)) VAL))
  7054.  
  7055. EVALUATE-LOCATIVE, EVALUATE-COND, EVALUATE-OR, EVALUATE-AND, EVALUATE-CASE, and
  7056. EVALUATE-LET   have   been   omitted  to  save  space;  their  definitions  are
  7057. uninteresting.  Each could be done either as a primitive ("fexpr"), as e.g.  IF
  7058. is  defined  above,  or  could  be  done using source-to-source transformations
  7059. (macros), using quasiquote and a single call to EVALUATE.
  7060.  
  7061.  
  7062.                                      -119-
  7063.  
  7064.  
  7065. Appendix B                                                            Libraries
  7066.  
  7067.  
  7068. This appendix describes various software packages which are not officially part
  7069. of  the T language but which are of general utility.  Some are available within
  7070. the implementations (Tau) directly, while others must be loaded  from  external
  7071. files using LOAD.
  7072.  
  7073. B.1. The data base     [REMOVED in T>3]                                            X13
  7074.  
  7075. The  data  base  is  a global two-dimensional sparse table indexed by arbitrary
  7076. objects.  Entries to the data base can be added, retrieved, and deleted via the
  7077. system procedures PROPERTY and REMOVE-PROPERTY.
  7078.  
  7079. By  being  a  global  resource,  the  data base violates a basic tenet of the T
  7080. design philosophy, that the system should have no  global  resources.    Global
  7081. resources  present  modularity  problems,  because  different programs may make
  7082. conflicting use of them.  In the case of the data base, program  A  might  make
  7083. use of data base entries whose second coordinate is the symbol FOO.  If program
  7084. B also makes use of such data base entries, but does not know (or want to know)
  7085. that  program  A  is already making use of those entries, then each program may
  7086. write over or be confused by the other's entries.
  7087.  
  7088. The data base corresponds to what is known in other Lisp dialects as  "property
  7089. lists."
  7090. (PROPERTY object1 object2) -> object                                   Settable
  7091. (GET object1 object2) -> object
  7092.  
  7093.      Access the data base entry indexed by object1 and object2.
  7094.  
  7095.          (SET (PROPERTY 'FOO 'COLOR) 'RED)    =>  RED
  7096.          (PROPERTY 'FOO 'COLOR)               =>  RED
  7097.          (SET (PROPERTY 'FOO 'COLOR) 'GREEN)  =>  GREEN
  7098.          (PROPERTY 'FOO 'COLOR)               =>  GREEN
  7099.  
  7100.           Bug: In Tau 2.7, object1 must be a symbol.
  7101.  
  7102.  
  7103. (SET-PROPERTY object1 object2 value) -> value                                  
  7104. (PUT object1 object2 value) -> value
  7105.  
  7106.      Sets the data base entry indexed by object1 and object2.
  7107.  
  7108.          (SET-PROPERTY object1 object2 value)
  7109.            <=>  (SET (PROPERTY object1 object2) value)
  7110.  
  7111.           Bug: In Tau 2.7, object1 must be a symbol.
  7112.  
  7113.  
  7114. (REMOVE-PROPERTY object1 object2) -> object or false                           
  7115.  
  7116.      REMOVE-PROPERTY  removes  the  data  base  entry  indexed  by  object1 and
  7117.      object2.  It returns false if there was no such entry.  (Note  that  there
  7118.      is no way to distinguish the absence of an entry from an entry whose value
  7119.      is false.)
  7120.  
  7121.                                      -120-
  7122.  
  7123.  
  7124. B.2. Symbol tables        [Removed from T>3]                                      X13
  7125.  
  7126. (MAKE-SYMBOL string) -> symbol                                                 
  7127.  
  7128.      Returns a new symbol whose print name is string.
  7129.  
  7130.  
  7131. A symbol table maps strings to symbols.
  7132. THE-SYMBOL-TABLE                                                             
  7133.  
  7134.      This variable holds the value of the standard system symbol table.    This
  7135.      is used implicitly by STRING->SYMBOL and READ.
  7136.  
  7137.  
  7138. (MAKE-SYMBOL-TABLE size) -> symbol-table                                       
  7139.  
  7140.      Creates  a  new  symbol  table,  suitable  as argument to INTERN and other
  7141.      symbol-table manipulation routines.
  7142.  
  7143.  
  7144. (INTERN string symbol-table) -> symbol                                         
  7145.  
  7146.      Looks in symbol-table for a symbol whose print name  is  STRING-EQUAL?  to
  7147.      string,  and  returns  it if one exists.  If not, it creates a new symbol,
  7148.      whose print name is a copy of string, and returns it.
  7149.  
  7150.  
  7151. (REALLY-INTERN string symbol-table) -> symbol                                  
  7152.  
  7153.      Similar to INTERN, except that if a new symbol  must  be  created,  string
  7154.      itself is used as the print name, not a copy of string.
  7155.  
  7156.  
  7157. (INTERNED string symbol-table) -> symbol or false                              
  7158.  
  7159.      Looks  in  symbol-table  for a symbol whose print name is STRING-EQUAL? to
  7160.      string.  Returns it if one exists, returns false otherwise.
  7161.  
  7162.  
  7163. (INTERNED? string symbol-table) -> boolean                                     
  7164.  
  7165.          (INTERNED? string symbol-table)
  7166.            <=>
  7167.          (TRUE? (INTERNED string symbol-table))
  7168.  
  7169.  
  7170. (WALK-SYMBOL-TABLE procedure symbol-table) -> undefined                        
  7171.  
  7172.      Procedure is called on each symbol in symbol-table.
  7173.  
  7174.  
  7175.                                      -121-
  7176.  
  7177.  
  7178. B.3. List utilities
  7179.  
  7180. (MEM predicate object list) -> list                                            
  7181.  
  7182.      Returns the first tail of list such that (predicate object (CAR tail)).
  7183.  
  7184.          (MEM EQ? 'A '(B A D E))  =>  (A D E)
  7185.  
  7186.  
  7187. (MEMQ object list) -> list                                                     
  7188.  
  7189.          (MEMQ object list)  <=>  (MEM EQ? object list)
  7190.  
  7191.  
  7192. (ANY predicate . lists) -> object                                              
  7193.  
  7194.      Calls the predicate on successive elements of the lists, stopping as  soon
  7195.      as the predicate returns a value other than false.  This value is returned
  7196.      as ANY's value.
  7197.  
  7198.          (ANY NUMBER? '(A B 3 FOO))  =>  true
  7199.          (ANY NUMBER? '(A B C FOO))  =>  false
  7200.          (ANY < '(1 2 3) '(6 6 6))   =>  true
  7201.          (ANY MEMQ '(A B C) '((X B) (U B Z) (C D E F)))  =>  (B Z)
  7202.  
  7203.  
  7204. (ANYCDR predicate . lists) -> object                                           
  7205.  
  7206.      Like ANY, but the predicate is called on successive  tails  of  the  lists
  7207.      instead of successive elements.
  7208.  
  7209.  
  7210. (EVERY predicate . lists) -> object                                            
  7211.  
  7212.      Calls  the predicate on successive elements of the lists, stopping as soon
  7213.      as the predicate returns false.  If for every  element  predicate  returns
  7214.      true, EVERY returns the value of the last call.
  7215.  
  7216.          (EVERY NUMBER? '(1 2 3 -15.7))  =>  true
  7217.          (EVERY NUMBER? '(1 2 3 FOO))    =>  false
  7218.          (EVERY ASSQ '(A B C)
  7219.               '(((A X) (X Y)) ((A J) (B K)) ((C D) (T U))))
  7220.            =>  (C D)
  7221.  
  7222.  
  7223. (EVERYCDR predicate . lists) -> object                                         
  7224.  
  7225.      Like  EVERY,  but the predicate is called on successive tails of the lists
  7226.      instead of successive elements.
  7227.  
  7228.  
  7229. (EVERYCDR? predicate . lists) -> boolean                                       
  7230.  
  7231.          (EVERYCDR? predicate . lists)  <=>  (TRUE? (EVERYCDR predicate . l
  7232.  
  7233.  
  7234. (ANYCDR? predicate . lists) -> boolean                                         
  7235.  
  7236.          (ANYCDR? predicate . lists)  <=>  (TRUE? (ANYCDR predicate . lists
  7237.  
  7238.                                      -122-
  7239.  
  7240.  
  7241. (POS predicate object list) -> integer or false                                
  7242.  
  7243.      Returns the position of the first item in list such that (predicate object
  7244.      item), or false if there is no such item.
  7245.  
  7246.  
  7247. (POSQ object list) -> integer or false                                         
  7248.  
  7249.          (POSQ object list)  <=>  (POS EQ? object list)
  7250.  
  7251.  
  7252. (APPEND-REVERSE list ending) -> list                                           
  7253.  
  7254.          (APPEND-REVERSE list ending)  <=>
  7255.            (APPEND (REVERSE list) ending)
  7256.  
  7257.          (APPEND-REVERSE '(A B C) '(D E))  =>  (C B A D E)
  7258.  
  7259.  
  7260. (APPEND-REVERSE! list ending) -> list                                          
  7261.  
  7262.          (APPEND-REVERSE! list ending)  <=>
  7263.          (APPEND! (REVERSE! list) ending)
  7264.  
  7265. B.4. Type-specific arithmetic
  7266.  
  7267. A  fixnum is an integer whose magnitude lies within an implementation-dependent
  7268. range.  This range is guaranteed to include all integers which  are  acceptable
  7269. as  array,  string,  or  vector  indices.   In Tau, this range is the half-open
  7270.            -28  28
  7271. interval [2   ,2  ).
  7272. (FIXNUM? object) -> boolean                                      Type predicate
  7273.  
  7274.      Returns true if object is a fixnum.
  7275.  
  7276.  
  7277. MOST-POSITIVE-FIXNUM -> integer                                                        
  7278.  
  7279.      Returns the largest integer value within the fixnum  range.    No  integer
  7280.      answering true to FIXNUM? is greater than this.
  7281.  
  7282.  
  7283. MOST-NEGATIVE-FIXNUM -> integer                                                        
  7284.  
  7285.      Returns  the  smallest  integer value within the fixnum range.  No integer
  7286.      answering true to FIXNUM? is less than this.
  7287.  
  7288.  
  7289. The following procedures are defined for performing type-restricted arithmetic.
  7290. These  procedures  should  be considered specializations of their corresponding
  7291. generic arithmetic procedures.  They assume restrictions on the types of  their
  7292. arguments  and  results.    The prefix FX means "fixnum-specific," and FL means
  7293. "flonum-specific."  For example,
  7294.  
  7295.     (FX+ x y)  <=>  (PROCLAIM FIXNUM? (+ (PROCLAIM FIXNUM? x) (PROCLAIM FIXNUM?y)))
  7296.  
  7297.                                      -123-
  7298.  
  7299.  
  7300. Tau will implement calls to these type-specific procedures in a more  efficient
  7301. manner than calls to the corresponding generic procedures.
  7302.  
  7303. The following list catalogs the available routines.  In most case the effect of
  7304. the procedure should be analogous to the example above.  The one  exception  is
  7305. FX/, which  is a  specialization  of the  truncated (integer) division  routine 
  7306. QUOTIENT, not of the division routine /.
  7307.  
  7308.     (FX+ fixnum1 fixnum2) -> fixnum
  7309.     (FL+ fixnum1 fixnum2) -> flonum
  7310.     (FX- fixnum1 fixnum2) -> fixnum
  7311.     (FL- flonum1 flonum2) -> flonum
  7312.     (FX* fixnum1 fixnum2) -> fixnum
  7313.     (FL* fixnum1 fixnum2) -> flonum
  7314.     (FX/ fixnum1 fixnum2) -> fixnum
  7315.     (FL/ flonum1 flonum2) -> flonum
  7316.     (FX= fixnum1 fixnum2) -> boolean
  7317.     (FL= flonum1 flonum2) -> boolean
  7318.     (FX< fixnum1 fixnum2) -> boolean
  7319.     (FL< flonum1 flonum2) -> boolean
  7320.     (FX> fixnum1 fixnum2) -> boolean
  7321.     (FL> flonum1 flonum2) -> boolean
  7322.     (FXN= fixnum1 fixnum2) -> boolean
  7323.     (FLN= flonum1 flonum2) -> boolean
  7324.     (FX>= fixnum1 fixnum2) -> boolean
  7325.     (FL>= flonum1 flonum2) -> boolean
  7326.     (FX<= fixnum1 fixnum2) -> boolean
  7327.     (FL<= flonum1 flonum2) -> boolean
  7328.     (FIXNUM-REMAINDER fixnum1 fixnum2) -> fixnum
  7329.     (FIXNUM-ODD? fixnum) -> boolean
  7330.     (FIXNUM-EVEN? fixnum) -> boolean
  7331.     (FIXNUM-ABS fixnum) -> fixnum
  7332.     (FIXNUM-MIN fixnum1 fixnum2) -> fixnum
  7333.     (FIXNUM-MAX fixnum1 fixnum2) -> fixnum
  7334.     (FIXNUM-LOGAND fixnum1 fixnum2) -> fixnum
  7335.     (FIXNUM-LOGIOR fixnum1 fixnum2) -> fixnum
  7336.     (FIXNUM-LOGNOT fixnum) -> fixnum
  7337.     (FIXNUM-ASHR fixnum) -> fixnum
  7338.     (FIXNUM-ASHL fixnum) -> fixnum
  7339.     (FIXNUM->FLONUM fixnum) -> flonum
  7340.     (FLONUM->FIXNUM flonum) -> fixnum
  7341.  
  7342.  
  7343.  
  7344. Appendix C                                           ASCII character conversion
  7345.  
  7346.  
  7347. The ASCII character set has nothing inherently to do with the T language or its
  7348. implementations.   Internally, any implementation is free to use any convenient
  7349. encoding for characters, for example, a modified ASCII (such  as  that  of  the
  7350. Lisp  Machine),  or  EBCDIC.    However,  the language does provide conversions
  7351. between characters and ASCII  codes  (CHAR->ASCII  and  ASCII->CHAR),  so  this
  7352. correspondence  is,  for the purposes of those routines, a part of the language
  7353. definition.  The table below is also provided as a general  reference,  because
  7354. people  using T are also likely to be using computers, and this information may
  7355. often be useful in that context.
  7356.  
  7357.                                      -124-
  7358.  
  7359.  
  7360.  8  10  16  charact| 8  10  16   charac|  8  10  16   chara|  8   10  16   char
  7361.  -  --  --  -------| -  --  --   ------|  -  --  --   -----|  -   --  --   ----
  7362.  0   0   0  #\NULL |40  32  20   #\SPAC|100  64  40   @    |140   96  60   `
  7363.  1   1   1         |41  33  21   !     |101  65  41   A    |141   97  61   a
  7364.  2   2   2         |42  34  22   "     |102  66  42   B    |142   98  62   b
  7365.  3   3   3         |43  35  23   #     |103  67  43   C    |143   99  63   c
  7366.  4   4   4         |44  36  24   $     |104  68  44   D    |144  100  64   d
  7367.  5   5   5         |45  37  25   %     |105  69  45   E    |145  101  65   e
  7368.  6   6   6         |46  38  26   &     |106  70  46   F    |146  102  66   f
  7369.  7   7   7  #\BELL |47  39  27   '     |107  71  47   G    |147  103  67   g
  7370. 10   8   8  #\BACKS|50  40  28   (     |110  72  48   H    |150  104  68   h
  7371. 11   9   9  #\TAB  |51  41  29   )     |111  73  49   I    |151  105  69   i
  7372. 12  10   A  #\LINEF|52  42  2A   *     |112  74  4A   J    |152  106  6A   j
  7373. 13  11   B         |53  43  2B   +     |113  75  4B   K    |153  107  6B   k
  7374. 14  12   C  #\FORM |54  44  2C   ,     |114  76  4C   L    |154  108  6C   l
  7375. 15  13   D  #\RETUR|55  45  2D   -     |115  77  4D   M    |155  109  6D   m
  7376. 16  14   E         |56  46  2E   .     |116  78  4E   N    |156  110  6E   n
  7377. 17  15   F         |57  47  2F   /     |117  79  4F   O    |157  111  6F   o
  7378. 20  16  10         |60  48  30   0     |120  80  50   P    |160  112  70   p
  7379. 21  17  11         |61  49  31   1     |121  81  51   Q    |161  113  71   q
  7380. 22  18  12         |62  50  32   2     |122  82  52   R    |162  114  72   r
  7381. 23  19  13         |63  51  33   3     |123  83  53   S    |163  115  73   s
  7382. 24  20  14         |64  52  34   4     |124  84  54   T    |164  116  74   t
  7383. 25  21  15         |65  53  35   5     |125  85  55   U    |165  117  75   u
  7384. 26  22  16         |66  54  36   6     |126  86  56   V    |166  118  76   v
  7385. 27  23  17         |67  55  37   7     |127  87  57   W    |167  119  77   w
  7386. 30  24  18         |70  56  38   8     |130  88  58   X    |170  120  78   x
  7387. 31  25  19         |71  57  39   9     |131  89  59   Y    |171  121  79   y
  7388. 32  26  1A         |72  58  3A   :     |132  90  5A   Z    |172  122  7A   z
  7389. 33  27  1B  #\ESCAP|73  59  3B   ;     |133  91  5B   [    |173  123  7B   {
  7390. 34  28  1C         |74  60  3C   <     |134  92  5C   \    |174  124  7C   |
  7391. 35  29  1D         |75  61  3D   =     |135  93  5D   ]    |175  125  7D   }
  7392. 36  30  1E         |76  62  3E   >     |136  94  5E   ^    |176  126  7E   ~
  7393. 37  31  1F         |77  63  3F   ?     |137  95  5F   _    |177  127  7F   #\RU
  7394.  
  7395.  
  7396.                                      -125-
  7397.  
  7398.  
  7399. Appendix D                                                         Equivalences
  7400.  
  7401.  
  7402. This is a cross-index for names of some of  the  more  common  primitives  from
  7403. other  Lisp  dialects  which  might  be similar to those in T. In the left hand
  7404. column is a list of names of functions found in other Lisps, and in the  center
  7405. are  likely  topics  to  look under in this document for similar functionality.
  7406. These function names are drawn from INTERLISP,  Lisp  1.5,  Lisp-Machine  Lisp,
  7407. Maclisp, SCHEME, UCI LISP, and Common Lisp.
  7408.  
  7409. The more obvious equivalences, for example, predicates where a name ending in P
  7410. corresponds to a T name ending in ?, have been omitted.
  7411.  
  7412.     For topic...             Look under...           On page...
  7413.     ASSOC . . . . . . . . .  ASS  . . . . . . . . .  49
  7414.     CASEQ . . . . . . . . .  CASE . . . . . . . . .  19
  7415.     CHAR-CODE . . . . . . .  CHAR->ASCII  . . . . .  67
  7416.     CHRCT . . . . . . . . .  HPOS . . . . . . . . .  93
  7417.     CHRTAB  . . . . . . . .  PORT-READ-TABLE    . .  93
  7418.     CLOSURE . . . . . . . .  LAMBDA . . . . . . . .  8
  7419.     CODE-CHAR . . . . . . .  ASCII->CHAR  . . . . .  67
  7420.     CONCAT  . . . . . . . .  CONCATENATE-SYMBOL . .  71
  7421.     CONSP . . . . . . . . .  PAIR?  . . . . . . . .  43
  7422.     CURSORPOS . . . . . . .  HPOS . . . . . . . . .  93
  7423.                           or VPOS . . . . . . . . .  93
  7424.     DEFFLAVOR . . . . . . .  OBJECT . . . . . . . .  31
  7425.     DEFMACRO  . . . . . . .  DEFINE-SYNTAX  . . . .  83
  7426.     DEFMETHOD . . . . . . .  OBJECT . . . . . . . .  31
  7427.     DEFPROP . . . . . . . .  PUT  . . . . . . . . .  120
  7428.  
  7429.     DEFSTRUCT . . . . . . .  DEFINE-STRUCTURE-TYPE   55
  7430.     DEFSUBST  . . . . . . .  DEFINE-INTEGRABLE  . .  71
  7431.     DEFUN . . . . . . . . .  DEFINE . . . . . . . .  15
  7432.     DEFVAR  . . . . . . . .  LSET . . . . . . . . .  15
  7433.     DEFVST  . . . . . . . .  DEFINE-STRUCTURE-TYPE   55
  7434.     DEF-OPEN-CODED  . . . .  DEFINE-INTEGRABLE  . .  71
  7435.     DELQ  . . . . . . . . .  DELQ!  . . . . . . . .  47
  7436.     DE  . . . . . . . . . .  DEFINE . . . . . . . .  15
  7437.     DF  . . . . . . . . . .  DEFINE-SYNTAX  . . . .  83
  7438.     DIFFERENCE  . . . . . .  SUBTRACT . . . . . . .  37
  7439.     DM  . . . . . . . . . .  DEFINE-SYNTAX  . . . .  83
  7440.     DREMOVE . . . . . . . .  DEL! . . . . . . . . .  47
  7441.     DREVERSE  . . . . . . .  REVERSE! . . . . . . .  47
  7442.     DSKIN . . . . . . . . .  LOAD . . . . . . . . .  102
  7443.     DSKLOG  . . . . . . . .  TRANSCRIPT-ON  . . . .  108
  7444.     DSKOUT  . . . . . . . .  WITH-OPEN-STREAMS  . .  87
  7445.     ENDP  . . . . . . . . .  NULL-LIST? . . . . . .  43
  7446.     EQUAL . . . . . . . . .  ALIKEV?  . . . . . . .  51
  7447.     EXPANDMACRO . . . . . .  MACRO-EXPAND . . . . .  86
  7448.     EXPLODE . . . . . . . .  STRING->LIST . . . . .  63
  7449.     FIXP  . . . . . . . . .  INTEGER? . . . . . . .  36
  7450.     FLATC . . . . . . . . .  DISPLAYWIDTH . . . . .  93
  7451.     FLATSIZE  . . . . . . .  PRINTWIDTH . . . . . .  93
  7452.     FUNCTION  . . . . . . .  LAMBDA . . . . . . . .  6
  7453.     GENSYM  . . . . . . . .  GENERATE-SYMBOL  . . .  71
  7454.     GETCHARN  . . . . . . .  STRING-ELT . . . . . .  64
  7455.     GETCHAR . . . . . . . .  STRING-ELT . . . . . .  64
  7456.     GET-PNAME . . . . . . .  SYMBOL->STRING . . . .  68
  7457.  
  7458.                                      -126-
  7459.  
  7460.  
  7461.     INTERN  . . . . . . . .  STRING->SYMBOL . . . .  68
  7462.     IOTA  . . . . . . . . .  WITH-OPEN-STREAMS  . .  87
  7463.     LABEL . . . . . . . . .  LABELS . . . . . . . .  10
  7464.     LAST  . . . . . . . . .  LASTCDR  . . . . . . .  45
  7465.     LIST* . . . . . . . . .  CONS*  . . . . . . . .  45
  7466.     LITATOM . . . . . . . .  SYMBOL?  . . . . . . .  6
  7467.     LOCF  . . . . . . . . .  LOCATIVE . . . . . . .  27
  7468.     MAKNAM  . . . . . . . .  STRING->SYMBOL . . . .  68
  7469.     MAPATOMS  . . . . . . .  WALK-SYMBOLS . . . . .  115
  7470.     MAPCAR  . . . . . . . .  MAP  . . . . . . . . .  48
  7471.     MAPC  . . . . . . . . .  WALK . . . . . . . . .  48
  7472.     MAPLIST . . . . . . . .  MAPCDR . . . . . . . .  48
  7473.     MAP . . . . . . . . . .  WALKCDR  . . . . . . .  48
  7474.     MCONS . . . . . . . . .  CONS*  . . . . . . . .  44
  7475.     MEMBER  . . . . . . . .  MEM  . . . . . . . . .  122
  7476.     MINUSP  . . . . . . . .  NEGATIVE?  . . . . . .  39
  7477.     MINUS . . . . . . . . .  NEGATE . . . . . . . .  37
  7478.     MSG . . . . . . . . . .  FORMAT . . . . . . . .  92
  7479.     NCONC . . . . . . . . .  APPEND!  . . . . . . .  46
  7480.     NCONS . . . . . . . . .  LIST . . . . . . . . .  44
  7481.     NRECONC . . . . . . . .  APPEND-REVERSE!  . . .  123
  7482.     NREVERSE  . . . . . . .  REVERSE! . . . . . . .  46
  7483.     NSUBSTRING  . . . . . .  STRING-SLICE . . . . .  64
  7484.     NTH . . . . . . . . . .  NTHCDR . . . . . . . .  45
  7485.     NUMBERP . . . . . . . .  NUMBER?  . . . . . . .  36
  7486.     PLUSP . . . . . . . . .  POSITIVE?  . . . . . .  39
  7487.     PLUS  . . . . . . . . .  ADD  . . . . . . . . .  37
  7488.     PNGET . . . . . . . . .  SYMBOL->STRING . . . .  68
  7489.     PRINC . . . . . . . . .  DISPLAY  . . . . . . .  91
  7490.     PRINC . . . . . . . . .  WRITES . . . . . . . .  90
  7491.     PRIN1 . . . . . . . . .  PRINT  . . . . . . . .  90
  7492.                           or WRITE  . . . . . . . .  90
  7493.     PROGN . . . . . . . . .  BLOCK  . . . . . . . .  23
  7494.     PROG1 . . . . . . . . .  BLOCK0 . . . . . . . .  23
  7495.     PUTPROP . . . . . . . .  PUT  . . . . . . . . .  120
  7496.     QUOTIENT  . . . . . . .  DIVIDE . . . . . . . .  37
  7497.     READCH  . . . . . . . .  READC  . . . . . . . .  88
  7498.     READLINE  . . . . . . .  READ-LINE  . . . . . .  89
  7499.     RECORD-TYPE . . . . . .  DEFINE-STRUCTURE-TYPE   55
  7500.     REMOVE  . . . . . . . .  DEL  . . . . . . . . .  47
  7501.     REMQ  . . . . . . . . .  DELQ . . . . . . . . .  47
  7502.     RETURN  . . . . . . . .  CATCH  . . . . . . . .  23
  7503.     RPLACA  . . . . . . . .  CAR  . . . . . . . . .  44
  7504.     RPLACD  . . . . . . . .  CDR  . . . . . . . . .  44
  7505.     SELECTQ . . . . . . . .  CASE . . . . . . . . .  19
  7506.     SETF  . . . . . . . . .  SET  . . . . . . . . .  25
  7507.     SETQ  . . . . . . . . .  SET  . . . . . . . . .  25
  7508.                           or LSET . . . . . . . . .  15
  7509.     SOME  . . . . . . . . .  ANYCDR . . . . . . . .  122
  7510.     SPECIAL . . . . . . . .  BIND . . . . . . . . .  28
  7511.     SPRINT  . . . . . . . .  PRETTY-PRINT . . . . .  91
  7512.     SPRINTER  . . . . . . .  PRINT  . . . . . . . .  91
  7513.     SUBST . . . . . . . . .  SUBSTV . . . . . . . .  52
  7514.     SUB1  . . . . . . . . .  SUBTRACT1  . . . . . .  37
  7515.     TAB . . . . . . . . . .  HPOS . . . . . . . . .  93
  7516.     TERPRI  . . . . . . . .  FRESH-LINE . . . . . .  91
  7517.                           or NEWLINE  . . . . . . .  91
  7518.     THROW . . . . . . . . .  CATCH  . . . . . . . .  23
  7519.     TIMES . . . . . . . . .  MULTIPLY . . . . . . .  37
  7520.     TTYMSG  . . . . . . . .  FORMAT . . . . . . . .  92
  7521.     TYIPEEK . . . . . . . .  PEEKC  . . . . . . . .  89
  7522.     TYI . . . . . . . . . .  READC  . . . . . . . .  89
  7523.     TYO . . . . . . . . . .  WRITEC . . . . . . . .  90
  7524.                                      -127-
  7525.  
  7526.  
  7527.     ZEROP . . . . . . . . .  ZERO?  . . . . . . . .  39
  7528.     1-  . . . . . . . . . .  SUBTRACT1  . . . . . .  37
  7529.     \ . . . . . . . . . . .  REMAINDER  . . . . . .  37
  7530.     //  . . . . . . . . . .  QUOTIENT . . . . . . .  37
  7531.  
  7532.     *CATCH  . . . . . . . .  CATCH  . . . . . . . .  23
  7533.     *THROW  . . . . . . . .  CATCH  . . . . . . . .  23
  7534.     :=  . . . . . . . . . .  SET  . . . . . . . . .  25
  7535.                           or MODIFY . . . . . . . .  25
  7536.     $EOF$ . . . . . . . . .  EOF  . . . . . . . . .  88
  7537.     ^G  . . . . . . . . . .  RESET  . . . . . . . .  107
  7538.  
  7539.                                      -128-
  7540.  
  7541.  
  7542. Appendix E                                                      Friendly advice
  7543.  
  7544.  
  7545. E.1. Comparison with other Lisp dialects
  7546.  
  7547. Some of the terminology may take some getting used to.  We always say procedure
  7548. instead  of function, for example.  Special form and reserved word have special
  7549. meaning.  Syntax usually refers not to what the reader does  but  to  what  the
  7550. compiler does.
  7551.  
  7552. As  in Common Lisp, but unlike most familiar Lisp dialects besides Scheme, T is
  7553. lexically scoped.
  7554.  
  7555. As in Scheme, there is full support for lexical  closures,  and  tail-recursive
  7556. calls are reliably performed as jumps.
  7557.  
  7558. Generic  operations  are  like  message-passing.  JOIN can be used to implement
  7559. object systems analogous to the Lisp Machine's flavor system.
  7560.  
  7561. Synonyms generalize Lisp Machine Lisp's MAKE-SYN-STREAM.
  7562.  
  7563. See also the equivalences appendix for some rough functional analogues.
  7564.  
  7565. E.2. Incompatibilities
  7566.  
  7567. The empty list is distinguished from the symbol  whose  print  name  is  "NIL".
  7568. That  is,  (NEQ?  NIL  'NIL).  The value of the variable NIL is the empty list.
  7569. The empty list is the same as the logical false value.
  7570.  
  7571. All "global" variables must be declared using LSET  before  they  are  assigned
  7572. using  SET  or  BIND.   This is quite unlike most Lisp dialects where the first
  7573. SETQ causes a variable to come into existence.
  7574.  
  7575. T has no FEXPR or NLAMBDA mechanism.  Their effect may  be  accomplished  using
  7576. procedures or macros.
  7577.  
  7578. There  are  no SPECIAL declarations and no implicit dynamic binding.  BIND must
  7579. be used explicitly when a variable is to be dynamically bound.
  7580.  
  7581. COND and CASE don't yield nil in the fall-through case;  they  yield  undefined
  7582. values.
  7583.  
  7584. RETURN and GO-tags are not supported in DO.  Lisp RETURN may be simulated using
  7585. (CATCH RETURN ...).
  7586.  
  7587. NTH is incompatible with Maclisp's function of the same name.  Maclisp's  takes
  7588. the  index  as  the  first  argument and the list as the second, instead of the
  7589. other way around.
  7590.  
  7591. LAST returns the last element of the list, not the last pair,  as  in  Maclisp.
  7592. Maclisp's LAST is like T's LASTCDR.
  7593.  
  7594. APPEND  isn't  defined  to  copy  all  but  the  last list.  I.e.  the language
  7595. definition allows the implementation to yield X, and not  a  copy  of  it,  for
  7596. (APPEND X '()).
  7597.  
  7598. PUSH's syntax is incompatible with that of PUSH in Maclisp and Common Lisp.
  7599.  
  7600. Locatives aren't as cheap as they are in Lisp Machine Lisp; creating a locative
  7601. may involve consing.
  7602.  
  7603.                                      -129-
  7604.  
  7605.  
  7606. Appendix F                                                          Future work
  7607.  
  7608.  
  7609. This appendix catalogs some ideas about T's future development.  It is provided
  7610. as a stimulus for user input, and as an assurance that these problems are known
  7611. and are being addressed.
  7612.  
  7613. F.1. Language design problems
  7614.  
  7615. A system for managing multiple namespaces --  loading  files  into  appropriate
  7616. environments,  and  communicating  names  from  one  module  to  another  in  a
  7617. controlled way -- is sorely needed.
  7618.  
  7619. Better aggregate structures are needed (arrays, hash tables).
  7620.  
  7621. Read macro procedures ought to take a read table as an argument.
  7622.  
  7623. A condition/error signalling system is needed.
  7624.  
  7625. Need to make up  for  the  loss  of  Scheme's  general  CATCH  by  implementing
  7626. coroutines.    Indeterminacy, timeslicing, and synchronization primitives would
  7627. be nice also.
  7628.  
  7629. Each special form should be marked as being either primitive or a macro.   This
  7630. would  allow users to write robust program-manipulating programs using only the
  7631. released language.
  7632.  
  7633. There should be a way to remove bindings from locales.
  7634.  
  7635. There ought to be able to have variables named by objects other  than  symbols.
  7636. Maybe there ought to be a generalized INTERN which creates a unique instance of
  7637. any object, or something like OWL's UCONS (unique cons) primitive.
  7638.  
  7639. Should reintroduce DEFINE-LOCALE?
  7640.  
  7641. MEMQ, ASSQ, POSQ, etc. are inconsistent  with  the  other  aggregate  accessing
  7642. routines in that the aggregate argument follows the index argument and not vice
  7643. versa.
  7644.  
  7645. Ideas for list routines: SUBSET, FILTER, FIND, set operations.
  7646.  
  7647. Need a term more specific than "tree" for whatever those things are.
  7648.  
  7649. The tree manipulation routines (e.g. ALIKEV?) should be user-extensible.    Big
  7650. problem with what TREE-HASH should do with unusual leaf nodes.
  7651.  
  7652. There  should  be a general way to do generic dispatches based on more than one
  7653. argument.
  7654.  
  7655. There should be a non-side-effecting way to define methods for structures.
  7656.  
  7657. SYNONYM is a misleading name.
  7658.  
  7659. SETTER is inadequate.  Why not PUSHER, SWAPPER, etc.?  Is there any way  to  do
  7660. this that's at the same time convenient, general, and efficient?
  7661.  
  7662. CASE and SELECT should use EQUIV? instead of EQ?.
  7663.  
  7664.                                      -130-
  7665.  
  7666.  
  7667. Method-clauses  aren't  incrementally  redefinable.    What  to  do about this.
  7668. Objects handling many operations become quite unmanageable.  Maybe this  is  an
  7669. implementation and editor problem, not a language problem.
  7670.  
  7671. The  looping/iteration  constructs  are  maybe a little too simple.  Figure out
  7672. some better ones without compromising principles, if possible.    Waters'  LetS
  7673. looks sort of good.
  7674.  
  7675. CHECK-ARG  is  ad  hoc.    Need type inference and other compiler smarts.  Need
  7676. better type declaration syntax.
  7677.  
  7678. There should be case-ignoring character and string comparison predicates.
  7679.  
  7680. STRING-POSQ is not a good name.
  7681.  
  7682. STRING-REPLACE   should   probably   be  called  STRING-REPLACE!,  or  flushed.
  7683. Similarly with VECTOR-FILL, VECTOR-REPLACE.
  7684.  
  7685. The name DIGIT? is nconsistent with DIGIT->CHAR -- does the term digit  mean  a
  7686. character or an integer?
  7687.  
  7688. What about UPPERCASE? -> UPPER-CASE??  Ugh.
  7689.  
  7690. Enumerated types.
  7691.  
  7692. Infinities?
  7693.  
  7694. Should NOT-ZERO? and friends be renamed to be NONZERO? etc.?
  7695.  
  7696. Divulge expression syntax for quasiquote?
  7697.  
  7698. Release WALK-WEAK-SET?  It's redundant, but handy.
  7699.  
  7700. Maybe release BOUND?.
  7701.  
  7702. Need a way to make read tables be read-only.
  7703.  
  7704. Need LET-SYNTAX-TABLE and LET-READ-TABLE features?
  7705.  
  7706. Maybe flush the random  not-parsable-as-number-implies-symbol  syntax  feature.
  7707. It can be a real pain to catch typos in numbers.
  7708.  
  7709. I/O system improvements needed:  
  7710.  
  7711.    - Ports   are pretty random.  How does a   port differ from a sequence?
  7712.      There should be ways to coerce from   ports to (infinite)  sequences,
  7713.      and  vice versa.  Maybe the term   port should follow Sussman's usage
  7714.      (infinte sequence), not Common Lisp's (pointer into same).
  7715.  
  7716.    - The FORMAT sublanguage is random and unextensible.
  7717.  
  7718.                                      -131-
  7719.  
  7720.  
  7721.    - Block-mode  and/or   "binary"   I/O,   for   database   or   whatever
  7722.      applications.
  7723.  
  7724.    - There  ought  to  be  a  way to make the printer complain if it comes
  7725.      across an object which isn't re-readable.
  7726.  
  7727.    - Ought to be a way to establish the line-length of a   port.
  7728.  
  7729.    - HPOS and VPOS aren't precisely defined.
  7730.  
  7731.    - SPACE operation needs a better definition.  
  7732.  
  7733. Structure package improvements needed:  
  7734.  
  7735.    - DEFINE-STRUCTURE-TYPE features: initializers, variant  record  types,
  7736.      arguments to constructor procedure, type-restricted fields, alternate
  7737.      name construction.
  7738.  
  7739.    - Maybe structures should have an official external syntax.
  7740.  
  7741.    - Structures ought to be callable.
  7742.  
  7743.    - COPY-STRUCTURE and COPY-STRUCTURE! ought to  take  as  an  additional
  7744.      argument   the   structure  type  to  which  the  structure  belongs.
  7745.      Alternatively, a copying  procedure  could  be  associated  with  the
  7746.      structure type object itself.
  7747.  
  7748.    - Maybe  there  ought  to be a way to test initializedness of structure
  7749.      components.  
  7750.  
  7751. F.2. Common Lisp influence
  7752.  
  7753. The design and implementation of T began around the same time that  the  Common
  7754. Lisp  design effort started in earnest.  Some of the goals of the projects have
  7755. been similar; in many cases, the T designers  left  certain  problems  for  the
  7756. Common  Lisp  designers to work out, intentionally ignoring many sticky issues,
  7757. such as numeric routines, sequences, and arrays, in  order  to  work  on  other
  7758. areas.
  7759.  
  7760. Now that the Common Lisp language has matured, and portable implementations are
  7761. approaching reality, two distinct integration projects are in order:  importing
  7762. ideas  and facilities from Common Lisp into T (with appropriate customization);
  7763. and building a Common Lisp emulation package in T.
  7764.  
  7765. T itself will never contain Common Lisp as a subset, but it should be  suitable
  7766. as  an  implementation language for a Common Lisp.  This will probably take the
  7767. form of alternate evaluator, reader, printer, and namespace,  together  with  a
  7768. Common Lisp-to-T translator.
  7769.  
  7770. The  following Common Lisp features, at least, should be incorporated into T in
  7771. some form:  
  7772.  
  7773.    - Arrays.
  7774.  
  7775.    - Sequences.  (These would clean up a lot of the current  clutter  with
  7776.      the  string  and  vector  routines,  but  introduce  a  new  level of
  7777.      implementation hair.)
  7778.  
  7779.    - Multiple values.  These  can  be  simulated  now  with  continuation-
  7780.      passing, but the syntax is clumsy.
  7781.  
  7782.                                      -132-
  7783.  
  7784.  
  7785.    - Numeric  routines.    Ratios  and complexes.  Multiple floating point
  7786.      precisions.
  7787.  
  7788.    - SHIFTF and ROTATEF.  (These are generalized versions of  T  SWAP  and
  7789.      EXCHANGE.)
  7790.  
  7791.    - Hash tables.
  7792.  
  7793.    - FORMAT enhancements: floating-point formats, etc.
  7794.  
  7795.    - File dates.  Time and date manipulation.  Time and date parsing.  
  7796.  
  7797. F.3. Bugs in the implementation
  7798.  
  7799. The  implementation  (Tau  2.7)  doesn't implement everything described in this
  7800. manual.
  7801.  
  7802.    - Not implemented:  ATAN2, JOIN, ROUND, PORT-POSITION, and  TRUNCATE.
  7803.  
  7804. Many things are implemented incorrectly.
  7805.  
  7806.    - Deficiencies  in syntax environments (they don't exist per se) and in         X3,&c.
  7807.      locales (shadowing loses).                                                    X8,&c.
  7808.  
  7809.    - GENERATE-SYMBOL:  The implementation  generates  obscure  names,  but
  7810.      doesn't guarantee uniqueness.  That is, the symbols are interned.
  7811.  
  7812.    - ANY? and EVERY? of more than one list don't work.
  7813.  
  7814.    - GET and PUT work only on symbols.
  7815.  
  7816.    - READ-LINE and UNREAD-CHAR interact badly.
  7817.  
  7818.    - There is no way to trace an operation.  
  7819.  
  7820. Many things are implemented less efficiently than they ought to be.
  7821.  
  7822.    - The garbage collector is slow.  This should be fixed.
  7823.  
  7824.    - There  ought  to  be  an  option  to  invoke the standard compiler on
  7825.      demand, as code is run, instead of all at once, as code is loaded.
  7826.  
  7827.    - BIND is implemented in a pretty cons-intensive way; there's a  bigger
  7828.      performance  penalty for dynamic binding than one would find in other
  7829.      Lisp implementations.
  7830.  
  7831.    - "Lexprs" are inefficient because they always  cons  a  list  for  the
  7832.      rest-variable.
  7833.  
  7834.    - The  i/o  system  doesn't  do  any  buffering; this really slows down
  7835.      reading and printing a lot, most notably the loading of code files.
  7836.  
  7837.    - Operation dispatch could be done using hash tables.  DEFINE-OPERATION
  7838.      needs  to do early binding.  This is feasible, but the implementation
  7839.      could become quite hairy.
  7840.  
  7841.    - Locales  are  permanent  (!),  and  forward  references  to  shadowed
  7842.      variables will lose big, especially with the standard compiler.
  7843.  
  7844.                                      -133-
  7845.  
  7846.  
  7847.    - The  interpreter  conses a lot more than it ought to.  It ought to do
  7848.      some small amount  of  closure  analysis,  or  else  use  McDermott's
  7849.      dynamic migration hack.
  7850.  
  7851.    - The  combinator  routines  are  pretty  useless since TC doesn't know
  7852.      anything about them.  This should be fixed.  For  example,  ((COMPOSE
  7853.      CAR  CDR)  '(A B C)) is evaluated, even in compiled code, by actually
  7854.      consing a procedure, and then invoking it.  
  7855.  
  7856. Many things in the system are implemented less smoothly than they ought to be.
  7857.  
  7858.    - Many system routines still don't  check  their  argument  types,  for
  7859.      example LOWERCASE? and UPPERCASE?.
  7860.  
  7861.    - Redefining  DEFINE-CONSTANT'ed  and DEFINE-INTEGRABLE'd should report
  7862.      an error condition.
  7863.  
  7864.    - Newline characters following input lines come out at the wrong  place
  7865.      in transcript files.
  7866.  
  7867.    - LOAD   ought   to   be   smarter   about  file  dates,  checking  for
  7868.      recompilation, etc.
  7869.  
  7870.    - Interpreted QUOTE ought to enforce read-only-ness.
  7871.  
  7872.    - There ought to be a way to enforce the downwards-only-ness of  escape
  7873.      procedures.  
  7874.  
  7875. Missing features.
  7876.  
  7877.    - SUSPEND and/or clean embedded-system-building tools.
  7878.  
  7879.    - Help system.
  7880.  
  7881.    - More  system  self-knowledge:  who  calls  x,  who  does x call, type
  7882.      analysis, etc.  Masterscope-like stuff.
  7883.  
  7884.    - Block compilation.
  7885.  
  7886.    - There should be a version of TRACE  which  destructively  modifies  a
  7887.      procedure so that it acts traced.
  7888.  
  7889.                                      -134-
  7890.  
  7891.  
  7892.                                                                      References
  7893.  
  7894.                                      -135-
  7895.  
  7896.  
  7897.                                                                           Index
  7898.  
  7899. ##   p106                                /   p37                              
  7900.                                                                               
  7901. '   p7                                   +   p37                             
  7902.                                                                               
  7903. *   p37                                  <   p37                              
  7904. *AND   p20                               <0?   p39                            
  7905. *COMMAND-LINE*   p106                    <=   p39                             
  7906. *DEFINE   p16                            <=0?   p39                           
  7907. *IF   p20                                <=>   p1                             
  7908. *LSET   p16                                                                
  7909.                                          ABS   p37                            
  7910. *NUMBER-OF-CHAR-CODES*                   ACOS   p39                           
  7911. *OR   p20                                ADD   p37                            
  7912. *VALUE   p16                             ADD-TO-WEAK-SET     p76              
  7913.                                          ADD1   p37                           
  7914. +   p37                                  AEGIS-FS?   p95                      
  7915.                                          ALIKE?   p51                         
  7916. -   p37                                  ALIKEQ?   p51                        
  7917. -1+   p37                                ALIKEV?   p51                        
  7918. ->   p1                                  ALPHABETIC?   p62                    
  7919. ->FILENAME   p95                         ALWAYS   p71                         
  7920. ->FLOAT   p39                            AND   p20                             
  7921. ->INTEGER   p39                          ANY  p122                            
  7922. ------------------------------------------------------------------------------
  7923. ANY?   p47                               BIND   p28                           
  7924. ANYCDR  p122                             BIT-FIELD   p39                      
  7925. ANYCDR?  p122                            BLOCK   p23                           
  7926. APPEND   p46                             BLOCK0   p23                          
  7927. APPEND!   p47                            BOOLEAN?   p73                       
  7928. APPEND-REVERSE  p122                     BREAKPOINT   p106                    
  7929. APPEND-REVERSE!  p122                    Backquote   p53,p77                  
  7930. APPLY   p23                              Bindings  p8f                        
  7931. ARGSPECTRUM  p114                                                             
  7932.  
  7933. ASCII codes   p125                       C...R   p46                          
  7934. ASCII->CHAR   p67                        CAR   p46                            
  7935. ASH   p39                                CASE   p20                           
  7936. ASIN   p39                               CATCH   p23                          
  7937. ASS   p47                                CDR   p46                            
  7938. ASSERT   p71                             CHAR   p62                           
  7939. ASSQ   p47                               CHAR->ASCII   p67                   
  7940. ATAN2   p39                              CHAR->DIGIT   p67                     
  7941. ATOM?   p46                              CHAR->STRING   p62                    
  7942. Access routines   p1                     CHAR-DOWNCASE   p62                   
  7943. Application  p8                          CHAR-UPCASE   p62                 
  7944. Arguments  p8                            CHAR<   p62                          
  7945. Assembly files  p103                     CHAR<=   p62                         
  7946. Association list   p47                   CHAR=   p62                           
  7947.                                          CHAR>   p62                           
  7948. BACKTRACE   p110                         CHAR>=   p62                          
  7949.  
  7950.                                   -136-
  7951.  
  7952.  
  7953. CHAR?   p62                              COS   p39                             
  7954. CHARN=   p62                             CRAWL   p110                          
  7955. CHDR   p62                               Call-by-name   p33                    
  7956. CHDR!   p62                              Call-by-need   p23                     
  7957. CHECK-ARG   p71                          Calling   p4                          
  7958. CHOPY   p62                              Calls   p4,p23                         
  7959. CHOPY!   p62                             Characters   p77                      
  7960. CLEAR-INPUT   p91                        Closure   p7                        
  7961. CLOSE   p89                              Combinators   p71                     
  7962. COMFILE  p103                            Command level   p106                  
  7963. COMMENT   p71                            Commands   p106                       
  7964. COMPLEMENT   p73                         Comments   p77                        
  7965. COMPOSE   p73                            Compilers   p101                  
  7966. CONCATENATE-SYMBOL   p71                 Conditionals   p5,p20                  
  7967. COND   p20                               Constituent characters   p77          
  7968. CONJOIN   p73                            Continuations   p110                  
  7969. CONS   p46                               Contours  p8f                         
  7970. CONS*   p46                              Core language   p4                    
  7971. CONTENTS   p27                                                                 
  7972. -------------------------------------------------------------------------------
  7973.  
  7974. COPY-LIST   p46                          DEBUG   p110                          
  7975. COPY-STRING   p62                        DEBUG-OUTPUT   p89                    
  7976. COPY-STRUCTURE   p57                     DECREMENT   p42                       
  7977. COPY-STRUCTURE!   p59                    DEFINE   p16                          
  7978. COPY-TREE   p51                          DEFINE-CONSTANT   p71                 
  7979. COPY-VECTOR   p73                        DEFINE-INTEGRABLE   p71               
  7980.  
  7981. DEFINE-LOCAL-SYNTAX   p86                Default methods   p30                 
  7982. DEFINE-OPERATION   p33                   Delays   p23                           
  7983. DEFINE-PREDICATE   p33                   Delimiter characters   p77            
  7984. DEFINE-SETTABLE-OPERATION   p33          Destructive   p47                     
  7985. DEFINE-STRUCTURE-TYPE   p57              Dot-notation   p1                     
  7986. DEFINE-SYNTAX   p80                      Dynamic binding   p27                 
  7987. DEL   p47                                Dynamic state  p23,p27                
  7988. DEL!   p47                                                                     
  7989.  
  7990. DELAY   p23                              ELSE   p11                          
  7991. DELIMITING-READ-MACRO?   p80             ENV   p101                            
  7992. DELQ   p47                               ENV-SYNTAX-TABLE   p80                
  7993. DELQ!   p47                              EOF   p89                             
  7994. DESTRUCTURE   p51                        EOF?   p89                            
  7995. DESTRUCTURE*   p51                       EQ?   p7                            
  7996. DIGIT   p67                              EQUAL?   p37                          
  7997. DIGIT->CHAR   p67                        EQUIV?   p51                          
  7998. DIGIT?   p62                             ERROR   p71                           
  7999. DISCLOSE  p114                           ERROR-OUTPUT   p89                    
  8000. DISJOIN   p73                            EVAL   p80                           
  8001. DISPLAY   p91                            EVEN?   p37                         
  8002. DISPLAYWIDTH   p94                       EVERY  p122                           
  8003. DIV   p37                                EVERY?   p47                          
  8004. DIVIDE   p37                             EVERYCDR  p122                        
  8005. DO   p23                                 EVERYCDR?  p122                       
  8006. Data base  p122                          EXCHANGE   p27                        
  8007.  
  8008.                                   -137-
  8009.  
  8010.  
  8011. EXIT   p106                              FILENAME-NAME   p95                   
  8012. EXP   p39                                FILENAME-TYPE   p95                   
  8013. EXPT   p37                               FILENAME?   p95                       
  8014. Early binding  p71,p101                  FIXNUM->FLONUM  p124                  
  8015. Early bindings.   p101                   FIXNUM-ABS  p124                      
  8016. Empty list   p7                          FIXNUM-ASHL  p124                     
  8017. End-of-file   p106                       FIXNUM-ASHR  p124                     
  8018. Environments   p4,p8f                    FIXNUM-EVEN?  p124                    
  8019. Equality predicates   p5,p51             FIXNUM-LOGAND  p124                   
  8020. Errors   p69,p110                        FIXNUM-LOGIOR  p124                   
  8021. Evaluation   p4,p82                      FIXNUM-LOGNOT  p124                   
  8022. Evaluator   p4                           FIXNUM-MAX  p124                      
  8023. Expression syntax   p4,p80               FIXNUM-MIN  p124                      
  8024. Expressions   p4                         FIXNUM-ODD?  p124                     
  8025. External representation   p4,p77         FIXNUM-REMAINDER  p124                
  8026.                                          FIXNUM?  p124                         
  8027. FALSE   p73                              FL*  p124                             
  8028. FALSE?   p20                             FL+  p124                             
  8029. FILE-DELETE   p99                        FL-  p124                             
  8030. FILE-EXISTS?   p99                       FL/  p124                             
  8031. FILE-MOVE   p99                          FL<  p124                             
  8032. FILENAME->STRING   p95                   FL<=  p124                            
  8033. FILENAME-DIR   p95                       FL=  p124                             
  8034. FILENAME-FS   p95                        FL>  p124                             
  8035. FILENAME-GENERATION   p95                FL>=  p124                            
  8036. -------------------------------------------------------------------------------
  8037.  
  8038. FLN=  p124                               Frames   p110                         
  8039. FLOAT?   p37                             Freelists   p73                       
  8040. FLONUM->FIXNUM  p124                     Functions   p107                       
  8041. FORCE  p24                               Functions, see Procedures             
  8042. FORCE-OUTPUT   p91                                                             
  8043.  
  8044. FORMAT   p91                             GC  p114                            
  8045. FRESH-LINE   p91                         GC-NOISILY?  p114                     
  8046. FX*  p124                                GC-STATS  p114                        
  8047. FX+  p124                                GCD   p37                             
  8048. FX-  p124                                GOBENERATE-SYMBOL   p71               
  8049. FX/  p124                                GET  p122                             
  8050. FX<  p124                                GET-ENVIRONMENT  p114                 
  8051. FX<=  p124                               GRAPHIC?   p62                        
  8052. FX=  p124                                GREATER?   p37                        
  8053. FX>  p124                                Garbage collection   p75f,p114         
  8054. FX>=  p124                                                                    
  8055.                                   -138-
  8056.  
  8057.  
  8058. FXN=  p124                               HPOS   p91                            
  8059. False   p7                               Handlers   p30                        
  8060. File system objects   p95                Hash code   p51                       
  8061. File systems   p95                       Hexadecimal   p77,p91                 
  8062. Filenames   p95                                                                
  8063.  
  8064. Files   p95,p99                          IDENTIFICATION  p114
  8065. Filespecs   p95                          IDENTITY   p71                       
  8066. Fixnums  p124                            IF   p20                               
  8067. Forms   p4                               IGNORABLE   p71                       
  8068.  
  8069. IGNORE   p71                             LABELS  p8f                          
  8070. IMPORT   p16                             LAMBDA   p7                            
  8071. INCREMENT   p39                          LAST   p46                            
  8072. INPUT-STREAM?   p89                      LASTCDR   p46                         
  8073. INTEGER?   p37                           LENGTH   p46                          
  8074. INTERACTIVE-STREAM?   p89                LESS?   p37                           
  8075. INTERN  p122                             LET  p8f                              
  8076. INTERNED  p122                           LET*  p8f                             
  8077. INVOKE-MACRO-EXPANDER   p86              LET-SYNTAX   p86                      
  8078. ITERATE   p23                            LINE-LENGTH   p91                     
  8079. Identifiers  p8f                         LIST   p46                            
  8080. Identity   p7                            LIST->STRING   p62                    
  8081. Implementation environment   p101        LIST->VECTOR   p73                    
  8082. Initialization file   p106               LIST-TERMINATOR   p81                 
  8083. Inspector   p110                         LIST?   p46                           
  8084. Interactive   p89                        LOAD   p101                           
  8085. Interrupts   p106                        LOAD-NOISILY?  p108                   
  8086. Invoking   p4                            LOCAL-FS   p95                        
  8087. Iteration   p20                          LOCALE   p16                          
  8088.                                          LOCALE?   p16                         
  8089. JOIN   p33                               LOCATIVE   p27                        
  8090. Joined objects   p33                     LOCATIVE?   p27                       
  8091.                                          LOG   p39                             
  8092. KWOTE   p86                              LOGAND   p39                          
  8093.                                          LOGIOR   p39                          
  8094. -------------------------------------------------------------------------------
  8095.  
  8096. LOGNOT   p39                             MAKE-WEAK-SET     p76                 
  8097. LOGXOR   p39                             MAKE-READ-TABLE   p77                 
  8098. LOWERCASE?   p62                         MAKE-STRING   p62                     
  8099. LSET   p16                               MAKE-STYPE   p57                      
  8100. Lazy evaluation   p23                    MAKE-SYMBOL  p122                     
  8101. Lexical scoping   p7                     MAKE-SYMBOL-TABLE  p122               
  8102. Lists   p4                               MAKE-SYNTAX-TABLE   p80               
  8103. Literals   p4,p7                         MAKE-VECTOR   p73                     
  8104. Loading   p101                           MAP   p47                             
  8105. Local file system   p95                  MAP!   p47                            
  8106. Local syntax   p86                       MAP-STRING   p62                      
  8107. Locales   p14f,p100                      MAP-STRING!   p62                     
  8108. Locations   p27                          MAPCDR   p47                          
  8109. Locatives   p27                          MAX   p37                             
  8110. Loops   p20                              MAYBE-OPEN   p99                      
  8111.                                          MEM  p122                             
  8112. MACRO-EXPAND   p86                       MEM?   p47                            
  8113. MACRO-EXPANDER   p86                     MEMQ  p122                            
  8114. MACRO-EXPANDER?   p86                    MEMQ?   p47                           
  8115. MAKE-BROADCAST-STREAM   p94              MIN   p37                             
  8116. MAKE-EMPTY-LOCALE   p16                  MOD   p37                             
  8117. MAKE-FILENAME   p95                      MODIFY   p27                          
  8118. MAKE-LIST-READER   p80                   MODIFY-LOCATION   p27                 
  8119. MAKE-LOCALE   p16                        MOST-NEGATIVE-FIXNUM  p124            
  8120. MAKE-POOL   p73                          MOST-POSITIVE-FIXNUM  p124            
  8121.                                   -139-
  8122.  
  8123.  
  8124. MULTIPLY   p37                           NULL?   p46                          
  8125. Macro expanders   p80                    NUMBER?   p37                        
  8126. Macros   p84,p114                        Noise files  p103              
  8127. Methods   p30                            Null   p7                              
  8128.                                          Numbers   p4,p36,p77                 
  8129. N=   p37                                                                      
  8130. N=0?   p39                               OBJECT   p30                         
  8131. NEGATE   p37                             OBJECT-HASH   p76                    
  8132. NEGATIVE?   p39                          OBJECT-UNHASH   p76                  
  8133. NEQ?   p7                                OBTAIN-FROM-POOL   p73               
  8134. NEWLINE   p91                            ODD?   p37                           
  8135. NIL   p7                                 OPEN   p99                           
  8136. NOT   p20                                OPERATION   p30                      
  8137. NOT-EQUAL?   p37                         OPERATION?   p30                     
  8138. NOT-GREATER?   p39                       OR   p20                             
  8139. NOT-LESS?   p39                          OUTPUT-STREAM?   p89                  
  8140. NOT-NEGATIVE?   p39                      Object files  p103                    
  8141. NOT-POSITIVE?   p39                      Objects   p4f,p30                   
  8142. NOT-ZERO?   p39                          Octal   p77,p91                       
  8143. NOTHING-READ     p80                     Operations   p30                      
  8144. NTH   p46                                
  8145. NTHCDR   p46                                                                   
  8146. NTHCHAR   p62                            PAIR?   p46                           
  8147. NTHCHDR   p62                            PEEK-CHAR   p89                       
  8148. NTHCHDR!   p62                           PEEKC   p89                           
  8149. NULL-LIST?   p46                         POP   p49                             
  8150. -------------------------------------------------------------------------------
  8151.  
  8152. POS  p122                                QUOTE   p6,p77                        
  8153. POSITIVE?   p39                          QUASIQUOTE   p53,p77                  
  8154. POSQ  p122                                                                     
  8155. PP   p110                                RATIO?   p37                          
  8156. PRETTY-PRINT   p91                       READ   p89                            
  8157. PRINT   p91                              READ-CHAR   p89                       
  8158. PRINTWIDTH   p91                         READ-ERROR   p71                      
  8159. PROCEDURE?   p23                         READ-LINE   p89                       
  8160. PROCLAIM   p71                           READ-OBJECT   p77                     
  8161. PROJ0   p71                              READ-OBJECTS-FROM-STRING   p91        
  8162. PROJ1   p73                              READ-REFUSING-EOF   p91               
  8163. PROJ2   p73                              READ-TABLE   p101                     
  8164. PROJ3   p73                              READ-TABLE-ENTRY   p80                
  8165. PROJN   p71                              READC   p89                           
  8166. PROPER-LIST?   p46                       REALLY-INTERN  p122                   
  8167. PROPERTY  p122                           RECKLESSNESS   p110                   
  8168. PUSH   p47                               REMAINDER   p37                       
  8169. PUT  p122                                REMOVE-FROM-WEAK-SET     p76          
  8170. Parentheses   p77                        REMOVE-PROPERTY  p122                 
  8171. Patch file   p106                        REPL-ENV   p106                       
  8172. Pools   p73                              REPL-EVAL  p108                       
  8173. Porphyrry   p0                           REPL-PRINT  p108                      
  8174. Predicates   p7                          REPL-PROMPT  p108                     
  8175. Procedures   p5,p23                      REPL-READ   p106                      
  8176.  
  8177.                                   -140-
  8178.  
  8179.  
  8180. REPL-WONT-PRINT  p108                    STANDARD-COMPILER   p80               
  8181. REPL-WONT-PRINT?  p108                   STANDARD-ENV   p101                   
  8182. RESET   p106                             STANDARD-INPUT   p89                  
  8183. RET   p106                               STANDARD-OUTPUT   p89                 
  8184. RETURN-TO-POOL   p76                     STANDARD-READ-TABLE   p77             
  8185. REVERSE   p47                            STANDARD-SYNTAX-TABLE   p80           
  8186. REVERSE!   p47                           STOP   p106                           
  8187. RUN-COMPILED-CODE   p80                  STREAM-FILENAME   p99                 
  8188. Read macros   p77                        STREAM-READ-TABLE   p91               
  8189. Read tables   p77                        STREAM?   p89                         
  8190. Read-eval-print loop   p106              STRING->INPUT-STREAM   p89            
  8191. Reader   p77                             STRING->LIST   p62                    
  8192. Reserved word   p4                       STRING->SYMBOL   p67                  
  8193. Reserved words   p80                     STRING-APPEND   p62                   
  8194. Routines   p7                            STRING-DOWNCASE   p62                 
  8195.                                          STRING-DOWNCASE!   p67                
  8196. SELECT   p20                             STRING-ELT   p62                      
  8197. SELECTOR-ID   p57                        STRING-EMPTY?   p62                   
  8198. SET   p27                                STRING-EQUAL?   p62                   
  8199. SET-BIT-FIELD   p39                      STRING-HEAD   p62                     
  8200. SET-PROPERTY  p122                       STRING-LENGTH   p62                   
  8201. SETTER   p27                             STRING-NTHTAIL   p62                  
  8202. SIN   p39                                STRING-NTHTAIL!   p62                 
  8203. SPACE   p91                              STRING-POSQ   p62                     
  8204. SQRT   p39                               STRING-REPLACE   p62                  
  8205. -------------------------------------------------------------------------------
  8206.  
  8207. STRING-SLICE   p62                       SYNONYM   p33                         
  8208. STRING-TAIL   p62                        SYNTAX-ERROR   p71                    
  8209. STRING-TAIL!   p62                       SYNTAX-TABLE   p101                   
  8210. STRING-UPCASE   p62                      SYNTAX-TABLE-ENTRY   p80              
  8211. STRING-UPCASE!   p62                     Scope   p6,p8f                         
  8212. STRING?   p62                            Scratch environment   p101            
  8213. STRUCTURE-TYPE  p114                     Semantics   p4                        
  8214. STRUCTURE?   p57                         Settable   p1                         
  8215. STYPE-CONSTRUCTOR   p57                  Shadowing  p8f                        
  8216. STYPE-HANDLER   p57                      Side-effects   p4,p27                 
  8217. STYPE-ID   p57                           Source files   p101                   
  8218. STYPE-MASTER   p57                       Special forms   p4,p80                
  8219. STYPE-PREDICATOR   p57                   Stack   p110                          
  8220. STYPE-SELECTOR   p57                     Standard environment   p4,p101        
  8221. STYPE-SELECTORS   p57                    State   p4,p27                        
  8222. SUBLIST   p47                            Streams   p89                         
  8223. SUBST   p51                              String headers   p62                  
  8224. SUBSTQ   p51                             String texts   p62                    
  8225. SUBSTRING   p62                          Strings   p77                         
  8226. SUBSTV   p51                             Structure types   p57                 
  8227. SUBTRACT   p37                           Structures   p57                      
  8228. SUBTRACT1   p37                          Stype   p57                           
  8229. SWAP   p27                               Support environments   p101           
  8230. SYMBOL->STRING   p67                     Support files  p103                   
  8231. SYMBOL?   p7                             Symbol tables  p122                   
  8232.  
  8233.                                    -141-
  8234.  
  8235.  
  8236. Symbols   p4,p6,p68,p77                  True   p7                             
  8237. Synonyms   p33                           Truth values   p7                     
  8238. Syntax descriptors   p80                 Type predicates   p7                   
  8239. Syntax tables   p77,p80                  Types   p8,p71                        
  8240.  
  8241. T   p8                                   UNDEFINED-EFFECT   p71                
  8242. T-IMPLEMENTATION-ENV  p114               UNDEFINED-VALUE   p71                 
  8243. T-VERSION-NUMBER   p115                  UNIX-FS?   p95                        
  8244. TAN   p39                                UNREAD-CHAR   p89                     
  8245. TC-ENV   p115                            UNREADC   p89                         
  8246. TC-MACRO-DEFINITION-ENV   p104           UNTRACE   p110                        
  8247. TC-SYNTAX-TABLE   p104                   UNWIND-PROTECT   p29                  
  8248. TERMINAL-INPUT   p89                     UPPERCASE?   p62                      
  8249. TERMINAL-OUTPUT   p89                    USER-ENV   p101                       
  8250. THE-SYMBOL-TABLE  p122                   Undefined   p1f,p71                    
  8251. TRACE   p110                             Undefined effects   p101              
  8252. TRANSCRIPT-OFF   p106                                                          
  8253. TRANSCRIPT-ON   p106                     VANILLA-READ-TABLE   p77              
  8254. TREE-HASH   p51                          VECTOR->LIST   p73                    
  8255. TRUE   p73                               VECTOR-ELT   p73                      
  8256. TRUE?   p73                              VECTOR-FILL   p73                     
  8257. Tests   p7                               VECTOR-LENGTH   p73                   
  8258. Throws   p23                             VECTOR-POS   p73                      
  8259. Transcript   p106                        VECTOR-POSQ   p73                     
  8260. Trees   p51                              VECTOR-REPLACE   p73                  
  8261. -------------------------------------------------------------------------------
  8262.  
  8263.  
  8264. VECTOR?   p73                            WITH-OUTPUT-TO-STRING   p89           
  8265. VMS-FS?   p95                            WITH-OUTPUT-WIDTH-STREAM   p91        
  8266. VPOS   p91                               WRITE   p91                           
  8267. VREF   p73                               WRITE-CHAR   p91                      
  8268. VSET   p73                               WRITE-LINE   p91                      
  8269. Values  p8f                              WRITE-SPACES   p91                    
  8270. Variables   p4,p8f                       WRITE-STRING   p91                    
  8271. Vectors   p77                            WRITEC   p91                          
  8272. Version numbers   p106                   WRITES   p91                          
  8273.                                          Weak pointers   p76                   
  8274. WALK   p47                               Weak sets   p76                       
  8275. WALK-STRING   p62                        Weight   p67                          
  8276. WALK-SYMBOL-TABLE  p122                  Whitespace?   p61,p77               
  8277. WALK-SYMBOLS  p114                       
  8278. WALK-VECTOR   p73                        XCASE   p18                          
  8279. WALK-WEAK-SET     p76                    XCOND   p18                            
  8280. WALKCDR   p47                            XSELECT   p19                         
  8281. Weak-sets   p76                        
  8282. WEAK-SET->LIST   p76                   
  8283. WHERE-DEFINED  p114                      Yield   p4                            
  8284. WHITESPACE?   p62                        
  8285. WITH-INPUT-FROM-STRING   p89             
  8286. WITH-OPEN-STREAMS   p89                  ZERO?   p39                           
  8287.                                          
  8288.                                   -142-
  8289.  
  8290.